#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
void amax(X& x, const Y& y) {
  if (x < y) x = y;
}
template <class X, class Y>
void amin(X& x, const Y& y) {
  if (x > y) x = y;
}
const int INF = 1e9 + 10;
const long long INFL = (long long)1e18 + 10;
int A, B, n;
bool check(int l, int r, int t, int m) {
  if ((long long)(r - 1) * B + A > t) return false;
  int len = r - l + 1;
  long long sum = (long long)A * len + (long long)(l - 1) * len * B;
  sum += (long long)(len - 1) * len / 2 * B;
  return sum <= (long long)t * m;
}
int bfind(int x, int t, int m) {
  int l = x, r = 1e7, i = (l + r) / 2;
  while (l != i && i != r) {
    if (check(x, i, t, m))
      l = i;
    else
      r = i;
    i = (l + r) / 2;
  }
  for (int i = r; i >= l; i--)
    if (check(x, i, t, m)) return i;
  return -1;
}
void process() {
  cin >> A >> B >> n;
  while (n--) {
    int l, t, m;
    cin >> l >> t >> m;
    cout << bfind(l, t, m) << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  process();
}
