#include <bits/stdc++.h>
using namespace std;
long long A, B, l, t, m, n;
long long look(long long loc) { return A + (loc - 1) * B; }
long long sum(long long start, long long end) {
  return (look(start) + look(end)) * (end - start + 1) / 2;
}
long long reverse_look(long long value) { return (value - A) / B + 1; }
long long fun() {
  long long left = l, right = reverse_look(t), mid;
  long long flag = right;
  while (left <= right) {
    mid = left + (right - left) / 2;
    if (sum(l, mid) <= m * t)
      left = mid + 1;
    else
      right = mid - 1;
  }
  if (left > flag) {
    if (sum(l, flag) <= m * t)
      return flag;
    else
      return -1;
  } else
    return left - 1;
}
int main() {
  while (cin >> A >> B >> n) {
    for (int i = 0; i < n; i++) {
      cin >> l >> t >> m;
      if (t < look(l)) {
        cout << "-1" << endl;
      } else {
        long long ret = fun();
        cout << ret << endl;
      }
    }
  }
  return 0;
}
