#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long power(long long x, long long y) {
  if (y == 0) return 1;
  long long u = power(x, y / 2);
  u = (u * u) % mod;
  if (y % 2) u = (x * u) % mod;
  return u;
}
long long gcd(long long a, long long b) {
  if (a < b) return gcd(b, a);
  return (b == 0 ? a : (a % b ? gcd(b, a % b) : b));
}
long long gcd_e(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1, y1;
  long long p = gcd_e(b, a % b, x1, y1);
  x = y1;
  y = x1 - (a / b) * y1;
  return p;
}
void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long get(long long a, long long b, long long x, long long y) {
  x--;
  y--;
  long long sum = (y * (y - 1) - x * (x - 1)) / 2;
  return a * (y - x) + sum * b;
}
int32_t main() {
  c_p_c();
  long long a, b, n;
  cin >> a >> b >> n;
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long ll = l;
    long long rr = 2e6 + 2;
    while (rr - ll > 1) {
      long long mid = (rr + ll) / 2;
      if (a + (mid - 2) * b <= t && get(a, b, l, mid) <= m * t) {
        ll = mid;
      } else
        rr = mid;
    }
    if (ll == l) ll = 0;
    cout << ll - 1 << endl;
  }
  return 0;
}
