#include <bits/stdc++.h>
using namespace std;
long long A, B, n, t, m;
long long h(int x) { return A + (x - 1) * B; }
bool judge(long long lef, long long loc) {
  long long hl = h(loc);
  long long temp = (long long)((loc + lef) * (loc - lef + 1) / 2 * B +
                               (loc - lef + 1) * (A - B));
  long long k = min(m, loc - lef + 1);
  if (temp % k == 0)
    temp = temp / k;
  else
    temp = temp / k + 1;
  if (t >= max(h(loc), temp))
    return 1;
  else
    return 0;
}
int main() {
  scanf("%I64d%I64d%I64d", &A, &B, &n);
  for (int i = 1; i <= n; i++) {
    long long l;
    scanf("%I64d%I64d%I64d", &l, &t, &m);
    long long lef = l, rig = 3000005;
    while (lef < rig) {
      long long mid = (rig + lef + 1) / 2;
      if (judge(l, mid))
        lef = mid;
      else
        rig = mid - 1;
    }
    if (!judge(l, lef))
      printf("-1\n");
    else
      printf("%I64d\n", lef);
  }
  return 0;
}
