#include <bits/stdc++.h>
using namespace std;
unsigned long long arr[1000005], ar[1000005];
unsigned long long A, B, l, t, m, n, tmp, r;
unsigned long long binarySearch(int a, int b) {
  int mid = (a + b) / 2;
  tmp = min(mid - l + 1, m);
  if (a == b) {
    if ((tmp * t < ar[mid] - ar[l - 1]) || (arr[a] > t)) return a - 1;
    return a;
  }
  if (arr[mid] > t) return binarySearch(a, mid);
  if (tmp * t > ar[mid] - ar[l - 1]) return binarySearch(mid + 1, b);
  return binarySearch(a, mid);
}
int main() {
  cin >> A >> B >> n;
  for (unsigned long long i = 1; i < 1000001; i++) {
    arr[i] = A + (i - 1) * B;
    ar[i] = ar[i - 1] + arr[i];
  }
  while (n--) {
    cin >> l >> t >> m;
    r = binarySearch(l, 1000000);
    if ((r < l) || ((r == l) && (arr[r] > t)))
      cout << "-1" << endl;
    else
      cout << r << endl;
  }
  return 0;
}
