#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n;
int T;
long long a, b;
long long all(long long e) { return e * (e + 1) / 2; }
long long As(long long s, long long e) { return (e - s + 1) * a; }
long long Bs(long long s, long long e) {
  long long start = all(s - 2);
  long long _end = all(e - 1);
  if (s - 2 < 0) start = 0;
  return (_end - start) * b;
}
int main() {
  cin >> a >> b >> T;
  while (T--) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long s = l, e = 1e9;
    while (s < e) {
      long long mid = (s + e + 1) >> 1;
      if (As(l, mid) + Bs(l, mid) <= t * m &&
          As(mid, mid) + Bs(mid, mid) <= t) {
        s = mid;
      } else {
        e = mid - 1;
      }
    }
    if (As(l, s) + Bs(l, s) <= t * m && As(l, l) + Bs(l, l) <= t) {
      cout << s << "\n";
    } else {
      cout << "-1\n";
    }
  }
}
