#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
int n;
long long a, b, l, t, m;
bool check(long long l, long long r, long long a, long long b, long long t,
           long long m) {
  long long d1 = r - l + 1;
  if (a + (r - 1) * b > t) {
    return false;
  }
  long long d2 = 2LL * a + (l + r - 2) * b;
  if (2LL * m * t / d1 >= d2) {
    return true;
  }
  return false;
}
int main() {
  cin >> a >> b >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld%lld%lld", &l, &t, &m);
    long long x = l, y = l + 1e12;
    while (x < y) {
      long long r = (x + y + 1) / 2;
      if (check(l, r, a, b, t, m)) {
        x = r;
      } else {
        y = r - 1;
      }
    }
    if (check(l, x, a, b, t, m)) {
      cout << x << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
