#include <bits/stdc++.h>
using namespace std;
long long int em(long long int x, long long int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return em((x % 1000000007 * x % 1000000007) % 1000000007, n / 2);
  else
    return (x % 1000000007 *
            em((x % 1000000007 * x % 1000000007) % 1000000007, (n - 1) / 2)) %
           1000000007;
}
long long int a, b;
long long int fun(long long int x) { return a + (x - 1) * b; }
long long int fun1(long long int x, long long int y) {
  return a * (y - x + 1) + b * ((y * (y - 1)) / 2 - ((x - 1) * (x - 2)) / 2);
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, i, j, k, l, t, m;
  cin >> a >> b >> n;
  while (n--) {
    cin >> l >> t >> m;
    long long int ans = -1;
    long long int li = l;
    long long int r = 1e9;
    while (li <= r) {
      long long int mid = r - (r - li) / 2;
      if (fun(mid) <= t && (fun1(l, mid) <= m * t)) {
        ans = max(ans, mid);
        li = mid + 1;
      } else
        r = mid - 1;
    }
    cout << ans << "\n";
  }
}
