#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000;
long long A, B, n, l, t, m, r;
bool check(long long len) {
  long long sum = A + (B * (l - 1));
  long long mx = A + (B * (len - 1));
  if (mx <= t && mx + sum <= 2 * m * t / (len - l + 1))
    return true;
  else
    return false;
}
long long BS(long long L, long long R) {
  if (L > R) return r;
  long long mid = L + R >> 1;
  if (check(mid)) {
    r = mid;
    return BS(mid + 1, R);
  } else
    return BS(L, mid - 1);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> A >> B >> n;
  while (n--) {
    cin >> l >> t >> m;
    r = l - 1;
    BS(l, INF);
    if (r >= l)
      cout << r << '\n';
    else
      cout << -1 << '\n';
  }
}
