#include <bits/stdc++.h>
using namespace std;
int n;
long long A, B;
long long l, t, m, mx;
void solve() {
  if ((A + (l - 1) * B) - t > 0) {
    cout << "-1" << endl;
    return;
  }
  long long left = 1, right = 1e7, ans = 0;
  long long len, mid;
  long long sum, L, R;
  long long p;
  while (left <= right) {
    len = mid = (left + right) / 2;
    R = l + len - 1;
    L = l;
    sum = ((A + (L - 1) * B) + (A + (R - 1) * B)) * len / 2;
    p = min(m, mid);
    long long temp = t * p;
    if (sum > temp || (A + (R - 1) * B) > t) {
      right = mid - 1;
    } else {
      left = mid + 1;
      ans = max(ans, len);
    }
  }
  cout << l + ans - 1 << endl;
}
int main() {
  cin >> A >> B >> n;
  while (n--) {
    cin >> l >> t >> m;
    solve();
  }
  return 0;
}
