#include <bits/stdc++.h>
using namespace std;
int INT_MAX_VAL = (int)1e20;
int INT_MIN_VAL = (int)-1e20;
long long LONG_MAX_VAL = (long long)1e20;
long long LONG_MIN_VAL = (long long)-1e20;
long long a, b, n;
long long func(long long l, long long r, long long m, long long t) {
  if (a + (r - 1) * b > t) return false;
  long long d = r - l + 1;
  long long prod = a * d + b * (r + l - 2) * d / 2;
  return prod <= (t * m);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b >> n;
  for (long long(T) = 0LL; (T) < (n); (T)++) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long cur = a + (l - 1) * b;
    if (cur > t) {
      cout << "-1" << '\n';
      continue;
    }
    long long lt = l;
    long long rt = 100000000;
    while (lt < rt) {
      long long med = (rt + lt + 1) / 2;
      if (func(l, med, m, t)) {
        lt = med;
      } else {
        rt = med - 1;
      }
    }
    cout << rt << '\n';
  }
  return 0;
}
