#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9, mod = 1e9 + 7, N = 3e5;
const long long linf = 1e18;
long long a, b, q;
long long sum(long long l, long long r) {
  return ((r - l + 1) * (a + (l - 1) * b + a + (r - 1) * b)) / 2;
}
int main() {
  scanf("%I64d%I64d%I64d", &a, &b, &q);
  for (int p = 0; p < q; p++) {
    long long l, t, m;
    scanf("%I64d%I64d%I64d", &l, &t, &m);
    long long L = l, R = 1e12;
    long long ans = -1;
    while (L <= R) {
      long long md = (L + R) >> 1;
      if (a + (md - 1) * b <= t && sum(l, md) <= t * m) {
        ans = md;
        L = md + 1;
      } else
        R = md - 1;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
