#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
long long int solve(long long int a, long long int b, long long int t,
                    long long int m) {
  if (a > t) {
    return -1;
  }
  long long int lo = 0;
  long long int hi = (t - a) / b + 2;
  while (hi - lo >= 2) {
    long long int mid = (lo + hi) / 2;
    bool ok = mid * (mid - 1) / 2 * b + a * mid <= m * t;
    if (mid <= m) {
      ok &= a + (mid - 1) * b <= t;
    }
    if (ok) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  return lo;
}
int main(void) {
  int a, b, n;
  cin >> a >> b >> n;
  for (int loop_var = (int)(0); loop_var < (int)(n); loop_var++) {
    long long int l, t, m;
    cin >> l >> t >> m;
    int res = solve((l - 1) * b + a, b, t, m);
    cout << (res == -1 ? -1 : res + l - 1) << endl;
  }
}
