#include <bits/stdc++.h>
using namespace std;
long long A, B;
long long l, m, t;
long n;
long long getD(long long i) { return A + (i - 1) * B; }
long long getSum(long long i) {
  long long sum = 0;
  sum = (getD(i) + getD(l)) * (i - l + 1) / 2;
  return sum;
}
void run() {
  scanf("%I64d %I64d %I64d", &A, &B, &n);
  while (n--) {
    scanf("%I64d %I64d %I64d", &l, &t, &m);
    if (getD(l) > t) {
      printf("-1\n");
      continue;
    }
    int ll = l;
    int lr = (t - A) / B + 1;
    int mid;
    while (ll <= lr) {
      mid = (ll + lr) / 2;
      if (getSum(mid) <= t * m)
        ll = mid + 1;
      else
        lr = mid - 1;
    }
    printf("%d\n", ll - 1);
  }
}
int main() {
  run();
  return 0;
}
