#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e8 + 9;
;
long long A, B, n;
long long l, t, m;
long long sum(long long k) { return A * k - B * k + ((k * (k + 1)) / 2) * B; }
bool ok(long long r) {
  long long x = A + B * (r - 1);
  if (x > t) return false;
  long long id = r - m + 1;
  if (id <= l) return true;
  long long rest = t - x;
  rest *= m;
  rest += ((m * (m - 1)) / 2) * B;
  id--;
  long long cur = sum(id) - sum(l - 1);
  if (cur > rest) return false;
  return true;
}
int get() {
  long long from = l;
  long long to = MAX;
  long long mid;
  while (to - from > 1) {
    mid = (from + to) / 2;
    if (ok(mid))
      from = mid;
    else
      to = mid;
  }
  if (ok(to)) return to;
  if (ok(mid)) return mid;
  return from;
}
int main() {
  cin >> A >> B >> n;
  long long r;
  for (int i = 0; i < n; i++) {
    cin >> l >> t >> m;
    if (A + (l - 1) * B > t) {
      cout << "-1\n";
      continue;
    }
    r = get();
    cout << r << endl;
  }
  return 0;
}
