#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 3;
const long long MOD = 1e9 + 7;
long long A, B, n;
long long S(long long n, long long a, long long d) {
  return ((2LL * a + (n - 1) * d) * n) / 2;
}
long long term(long long i) { return A + (i - 1) * B; }
long long check(long long L, long long m, long long t, long long x) {
  if (t < term(L + x - 1)) return false;
  long long tot = S(x, term(L), B);
  long long lagbe = (tot / m) + (tot % m > 0);
  return lagbe <= t;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> A >> B >> n;
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    if (!check(l, m, t, 1)) {
      cout << "-1\n";
      continue;
    }
    long long lo = 1, hi = 1e6;
    while (hi > lo) {
      long long mid = (lo + hi + 1) / 2;
      if (check(l, m, t, mid))
        lo = mid;
      else
        hi = mid - 1;
    }
    cout << l + lo - 1 << "\n";
  }
}
