#include <bits/stdc++.h>
using namespace std;
long long a, b, n, l, t, m;
long long ans1, ans2;
long long f(long long x) { return a + (x - 1) * b; }
long long fin() {
  long long ll = 1,
            rr = sqrt((2 * m * t + (l - 1) * (2 * a + l * b - 2 * b)) / b),
            mid = -1;
  while (mid != (ll + rr) / 2) {
    mid = (ll + rr) / 2;
    if (((a + (l - 1) * b + a + (mid - 1) * b) * (mid - l + 1)) / 2 > m * t)
      rr = mid;
    else
      ll = mid;
  }
  mid += 10;
  while (((a + (l - 1) * b + a + (mid - 1) * b) * (mid - l + 1)) / 2 > m * t) {
    mid--;
  }
  return mid;
}
int main() {
  cin >> a >> b >> n;
  while (n--) {
    cin >> l >> t >> m;
    if (t < a + (l - 1) * b)
      printf("-1\n");
    else {
      ans1 = (t - a) / b + 3;
      while (f(ans1) > t) ans1--;
      ans2 = fin();
      cout << min(ans1, ans2) << endl;
    }
  }
  return 0;
}
