#include <bits/stdc++.h>
using namespace std;
int a, b, m, t;
long long sum(int l, int r) {
  long long sl = a + (l - 1) * b;
  long long sr = a + (r - 1) * b;
  return (sl + sr) * (r - l + 1) / 2;
}
bool chk(int l, int x) {
  return a + 1LL * (x - 1) * b <= 1LL * t && sum(l, x) <= 1LL * m * t;
}
int main(void) {
  int q;
  cin >> a >> b >> q;
  while (q--) {
    int l;
    cin >> l >> t >> m;
    int lo = l - 1, hi = 1000000000;
    while (lo != hi) {
      int mi = (lo + hi + 1) / 2;
      if (chk(l, mi))
        lo = mi;
      else
        hi = mi - 1;
    }
    if (lo < l)
      cout << "-1\n";
    else
      cout << lo << "\n";
  }
  return 0;
}
