#include <bits/stdc++.h>
using namespace std;
long long A, B, n, l, t, m;
int main() {
  cin >> A >> B >> n;
  while (n--) {
    cin >> l >> t >> m;
    long long r = (t - A) / B + 1;
    if (r < l) {
      cout << "-1" << endl;
      continue;
    }
    r++;
    long long st = l;
    while (st + 1 < r) {
      long long mid = (st + r) / 2;
      long long sum = B * (mid - l + 1) * (mid + l - 2) / 2 + (mid - l + 1) * A;
      if (t * m >= sum) {
        st = mid;
      } else {
        r = mid;
      }
    }
    cout << r - 1 << endl;
  }
}
