#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
long long a, b, n, l, t, m;
long long sum(long long mid) {
  return a * mid + mid * (mid - 1) / 2 * b - a * (l - 1) -
         (l - 1) * (l - 2) / 2 * b;
}
int main() {
  cin >> a >> b >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> l >> t >> m;
    if (sum(l) > t) {
      cout << -1 << endl;
      continue;
    }
    long long R = l + t, L = l, mid;
    while (R >= L) {
      mid = (L + R) >> 1;
      if (sum(mid) <= t * m && a + (mid - 1) * b <= t)
        L = mid + 1;
      else
        R = mid - 1;
    }
    cout << L - 1 << endl;
  }
  return 0;
}
