#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const unsigned long long mod = 1e9 + 7;
bool check(unsigned long long L, unsigned long long R, unsigned long long n,
           unsigned long long t, unsigned long long m) {
  if (R > t) return false;
  unsigned long long tot = (L + R) * n / 2;
  return t * m >= tot;
}
int main(int argc, char const *argv[]) {
  unsigned long long a, b, n;
  while (cin >> a >> b >> n) {
    while (n--) {
      unsigned long long L, R, t, m;
      cin >> L >> t >> m;
      R = 2e6;
      unsigned long long a0 = a + (L - 1) * b, Lt = L;
      if (a0 > t) {
        puts("-1");
        continue;
      }
      while (L + 1 < R) {
        unsigned long long mid = (L + R) >> 1;
        if (check(a0, a + (mid - 1) * b, mid - Lt + 1, t, m))
          L = mid;
        else
          R = mid;
      }
      cout << L << endl;
    }
  }
  return 0;
}
