#include <bits/stdc++.h>
using namespace std;
long long A, B, N;
long long l, t, m;
int main() {
  cin >> A >> B >> N;
  for (int i = 0; i < N; i++) {
    cin >> l >> t >> m;
    if (t < A + (l - 1) * B) {
      cout << -1 << endl;
    } else {
      long long left = l, right = (t - A) / B + 1;
      while (left <= right) {
        long long mid = (left + right) / 2;
        long long sum = (mid - l + 1) * (2 * A + B * (mid + l) - 2 * B) / 2;
        if (sum <= m * t) {
          left = mid + 1;
        } else {
          right = mid - 1;
        }
      }
      cout << right << endl;
    }
  }
  return 0;
}
