#include <bits/stdc++.h>
using namespace std;
long long A, B, l, t, m;
long long X1(int i) { return A + (i - 1) * B; }
bool check(int i) {
  if (X1(i) > t) return false;
  long long S = (X1(l) + X1(i)) * (i - l + 1) / 2;
  long long tmp = max(S % m == 0 ? S / m : S / m + 1, X1(i));
  if (tmp > t) return false;
  return true;
}
int main() {
  int n;
  cin >> A >> B >> n;
  while (n--) {
    cin >> l >> t >> m;
    long long x = A + B * (l - 1);
    if (x > t)
      printf("-1\n");
    else {
      int L = l, R = 1000010;
      while (L < R) {
        int mid = (L + R) >> 1;
        if (L == mid) mid = R;
        if (check(mid))
          L = mid;
        else
          R = mid - 1;
      }
      printf("%d\n", L);
    }
  }
  return 0;
}
