#include <bits/stdc++.h>
using namespace std;
long long A, B, n, l, t, m;
bool check(long long x) {
  long long n = x - l + 1;
  long long a1 = A + B * (l - 1);
  long long an = A + B * (x - 1);
  long long sum = (a1 + an) * n / 2;
  return sum <= t * m && an <= t;
}
int binary() {
  long long le = l, ri = t;
  while (le + 1 < ri) {
    int mid = (le + ri) >> 1;
    if (check(mid))
      le = mid;
    else
      ri = mid;
  }
  if (!check(le)) return -1;
  return check(ri) ? ri : le;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> A >> B >> n;
  while (n--) {
    cin >> l >> t >> m;
    cout << binary() << endl;
  }
  return 0;
}
