#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 100;
long long A, B;
int n;
int l, t, m;
long long sum(int i) {
  return (long long)i * A + B * ((long long)i * (i - 1) / 2);
}
bool judge(int L, int R) {
  long long remain = sum(R) - sum(L - 1);
  long long cnt = remain / m;
  if (remain % m) cnt++;
  return max(cnt, A + B * (R - 1)) <= (long long)t;
}
int main() {
  scanf("%lld %lld %d", &A, &B, &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d", &l, &t, &m);
    if (!judge(l, l)) {
      puts("-1");
      continue;
    }
    int L = l, R = 10000000;
    while (R >= L) {
      int mid = (L + R) >> 1;
      if (judge(l, mid))
        L = mid + 1;
      else
        R = mid - 1;
    }
    printf("%d\n", R);
  }
  return 0;
}
