#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
long long a, b, n;
long long l, t, m;
long long cal(long long x) { return a + (x - 1) * b; }
long long getsum(long long r) { return (cal(r) + cal(l)) * (r - l + 1) / 2; }
int main() {
  long long i, j, k, maxn;
  while (~scanf("%I64d%I64d%I64d", &a, &b, &n)) {
    while (n--) {
      scanf("%I64d%I64d%I64d", &l, &t, &m);
      if (cal(l) > t) {
        printf("-1\n");
        continue;
      }
      long long ll = l, lr = (t - a) / b + 1, mid;
      while (ll <= lr) {
        long long mid = (ll + lr) / 2;
        if (getsum(mid) <= t * m)
          ll = mid + 1;
        else
          lr = mid - 1;
      }
      printf("%d\n", ll - 1);
    }
  }
  return 0;
}
