#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, n;
  cin >> a >> b >> n;
  long long l, t, m;
  for (int i = 0; i < n; ++i) {
    cin >> l >> t >> m;
    long long sl = a + b * (l - 1), sr;
    if (t < sl) {
      cout << -1 << endl;
      continue;
    }
    int lf = l, rt = (t - a) / b + 1;
    int r = (lf + rt) / 2;
    while (lf != r) {
      sr = a + b * (r - 1);
      if ((sl + sr) * (r - l + 1) / 2 <= t * m) {
        lf = r;
      } else {
        rt = r - 1;
      }
      r = (lf + rt) / 2;
    }
    if ((sl + a + b * (rt - 1)) * (rt - l + 1) / 2 <= t * m) {
      r = rt;
    }
    cout << r << endl;
  }
  return 0;
}
