#include <bits/stdc++.h>
using namespace std;
const int N = 2000000 + 10;
long long A, B, n;
long long sum[N], a[N];
int main() {
  cin >> A >> B >> n;
  a[1] = A;
  for (int i = 1; i <= 2000000; i++) {
    sum[i] = sum[i - 1] + a[i];
    a[i + 1] = a[i] + B;
  }
  for (int i = 1; i <= n; i++) {
    int l, t, m;
    cin >> l >> t >> m;
    int r1 =
        upper_bound(sum + l, sum + 2000001, sum[l - 1] + (long long)t * m) -
        sum;
    int r2 = upper_bound(a + l, a + 2000001, (long long)t) - a;
    int r = min(r1, r2);
    if (r == l)
      puts("-1");
    else
      cout << r - 1 << endl;
  }
  return 0;
}
