#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10, mod = 1e9 + 7;
int A, B, n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> A >> B >> n;
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    if ((1LL * (A + (l - 1) * B)) > t) {
      cout << -1 << '\n';
      continue;
    }
    long long L = l, R = L + maxn, M = (R + L) / 2;
    while (R - L > 1) {
      if ((1LL * ((1LL * (A + (l - 1) * B)) + (1LL * (A + (M - 1) * B))) *
           (M - l + 1) / 2) <= t * m &&
          (1LL * (A + (M - 1) * B)) <= t) {
        L = M;
      } else {
        R = M;
      }
      M = (R + L) / 2;
    }
    cout << L << '\n';
  }
  return 0;
}
