#include <bits/stdc++.h>
using namespace std;
long long a, b, n;
long long l, t, m;
long long Caculate(long long i) { return a + (i - 1) * b; }
bool Can(long long mid) {
  long long temp = (Caculate(l) + Caculate(mid)) * (mid - l + 1) / 2;
  if (temp <= t * m) return true;
  return false;
}
int main() {
  scanf("%I64d %I64d %I64d", &a, &b, &n);
  for (long long i = 0; i < n; i++) {
    scanf("%I64d %I64d %I64d", &l, &t, &m);
    if (Caculate(l) > t)
      cout << -1 << endl;
    else {
      long long lb = 0, rb = (t - a) / b + 1;
      while (rb >= lb) {
        long long mid = (lb + rb) / 2;
        if (Can(mid))
          lb = mid + 1;
        else
          rb = mid - 1;
      }
      printf("%I64d\n", lb - 1);
    }
  }
  return 0;
}
