#include <bits/stdc++.h>
using namespace std;
const int N = 100007;
long long A, B, n, l, r, t, m;
long long get(long long x) { return A + (x - 1) * B; }
long long sum(long long x) {
  if (x < 1) return 0;
  return x * A + (x - 1) * x / 2 * B;
}
bool check(long long x) {
  long long tmp = sum(x) - sum(l - 1);
  if (tmp > t * m)
    return false;
  else
    return true;
}
long long solve() {
  long long ans;
  long long ll = l, rr = r;
  while (ll <= rr) {
    long long mid = (ll + rr) >> 1;
    if (check(mid)) {
      ans = mid;
      ll = mid + 1;
    } else
      rr = mid - 1;
  }
  return ans;
}
int main() {
  while (scanf("%I64d%I64d%I64d", &A, &B, &n) == 3) {
    while (n--) {
      scanf("%I64d %I64d %I64d", &l, &t, &m);
      if (t < get(l)) {
        printf("-1\n");
        continue;
      }
      r = (t - A + B) / B;
      printf("%I64d\n", solve());
    }
  }
  return 0;
}
