#include <bits/stdc++.h>
using namespace std;
long long sum(long long a0, long long n, long long B) {
  return n * (2 * a0 + (n - 1) * B);
}
int main() {
  long long A, B, n;
  cin >> A >> B >> n;
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long a = A + B * (l - 1);
    if (a > t) {
      cout << "-1" << endl;
      continue;
    }
    long long lo = 0, mid, hi = 1000001, iter = 60;
    while (hi > lo && iter--) {
      mid = (lo + hi) / 2;
      if (sum(a, mid + 1, B) > 2 * m * t || a + B * mid > t)
        hi = mid;
      else
        lo = mid + 1;
    }
    if (lo < 1)
      cout << "-1" << endl;
    else
      cout << l + lo - 1 << endl;
  }
  return 0;
}
