#include <bits/stdc++.h>
using namespace std;
long long getSum(long long n, long long A, long long B) {
  return n * A + B * (n - 1) * n / 2;
}
bool f(long long l, long long r, long long t, long long m, long long A,
       long long B) {
  long long maxValue = A + (r - 1) * B;
  if (maxValue > t) return false;
  long long sum = getSum(r, A, B) - getSum(l - 1, A, B);
  if (sum <= t * m) return true;
  return false;
}
void solve(long long l, long long t, long long m, long long A, long long B) {
  long long L = l, R = (long long)1e9;
  while (R - L > 1) {
    long long mid = (L + R) / 2;
    if (f(l, mid, t, m, A, B))
      L = mid;
    else
      R = mid;
  }
  long long answer;
  if (f(l, R, t, m, A, B))
    answer = R;
  else if (f(l, L, t, m, A, B))
    answer = L;
  else
    answer = -1;
  cout << answer << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long A, B;
  int test;
  cin >> A >> B >> test;
  for (int tst = 1; tst <= test; ++tst) {
    long long l, t, m;
    cin >> l >> t >> m;
    solve(l, t, m, A, B);
  }
  return 0;
}
