#include <bits/stdc++.h>
using namespace std;
long long a, b, n, l, tests, t, m, lo, mid, hi;
long long getSum(long long l, long long r) {
  long long dim = r - l + 1;
  long long ans = dim * (a + b * (l - 1)) + ((dim * (dim - 1)) / 2) * b;
  return ans;
}
long long min(long long a, long long b) { return (a < b ? a : b); }
int main() {
  cin >> a >> b >> tests;
  while (tests--) {
    cin >> l >> t >> m;
    if (getSum(l, l) > t * m) {
      cout << "-1\n";
      continue;
    }
    lo = l - 1;
    hi = 10000LL * 10000LL;
    while (hi - lo > 1) {
      mid = (lo + hi) / 2LL;
      if (getSum(l, mid) <= t * min(m, mid - l + 1) && getSum(mid, mid) <= t)
        lo = mid;
      else
        hi = mid;
    }
    if (lo == l - 1)
      cout << "-1\n";
    else
      cout << lo << "\n";
  }
  return 0;
}
