#include <bits/stdc++.h>
using namespace std;
long long int A, B;
int N;
long long int getIthSum(long long int r) {
  return r * A + (((r - 1) * r) / 2) * B;
}
bool satisfies(long long int l, long long int r, long long int t,
               long long int m) {
  long long int rElement = (r - 1) * B + A;
  if (rElement > t) {
    return false;
  }
  long long int lElement = (l - 1) * B + A;
  long long int sum = getIthSum(r) - getIthSum(l) + lElement;
  if (sum > m * t) {
    return false;
  }
  return true;
}
int smallestR(long long int l, long long int t, long long int m) {
  long long int leftmost = l;
  long long int rightmost = 1000000;
  long long int mid = (leftmost + rightmost) / 2;
  while (rightmost - leftmost > 2) {
    if (satisfies(l, mid, t, m)) {
      leftmost = mid;
    } else {
      rightmost = mid;
    }
    mid = (leftmost + rightmost) / 2;
  }
  int maxRes = -1;
  for (int i = leftmost; i <= rightmost; i++) {
    if (satisfies(l, i, t, m)) {
      maxRes = i;
    }
  }
  return maxRes;
}
int main() {
  cin >> A >> B >> N;
  for (int i = 0; i < N; i++) {
    long long int l, t, m;
    cin >> l >> t >> m;
    cout << smallestR(l, t, m) << endl;
  }
  return 0;
}
