#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
long long int a, b, n;
long long int L, t, m;
long long int f(long long int x) { return a + (x - 1) * b; }
bool solve(long long int mid) {
  long long int n = mid - L + 1;
  return n * f(L) + n * (n - 1) * b / 2 <= t * m;
}
int main() {
  cin >> a >> b >> n;
  while (n--) {
    cin >> L >> t >> m;
    if (f(L) > t) {
      puts("-1");
      continue;
    }
    long long int l = 1, r = (t - a) / b + 1, mid;
    long long int ans;
    while (r >= l) {
      mid = l + r >> 1;
      if (solve(mid))
        l = mid + 1, ans = mid;
      else
        r = mid - 1;
    }
    cout << ans << endl;
  }
}
