#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long MAX = 1e17;
long long a, b, n;
long long m, t;
long long check(long long l, long long x) {
  long long ans = (x - l + 1) * a + b * (l - 1) * (x - l + 1) +
                  (b * (x - l) * (x - l + 1)) / 2;
  if (a + (x - 1) * b > t) return m * t + 1;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  ;
  cin >> a >> b >> n;
  while (n--) {
    long long L;
    cin >> L >> t >> m;
    long long l = L, r = L + m * t;
    while (r - l > 1) {
      long long mid = (l + r) / 2;
      if (check(L, mid) <= (min(m, mid - L + 1)) * t)
        l = mid;
      else
        r = mid;
    }
    if (check(L, r) > (min(m, r - L + 1)) * t) r = l;
    if (check(L, l) > (min(m, l - L + 1)) * t) r = -1;
    cout << r << endl;
  }
}
