#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N = 1e5;
int main() {
  long long A, B, n, l, t, m;
  cin >> A >> B >> n;
  for (int i = 1; i <= n; i++) {
    cin >> l >> t >> m;
    long long Sl = A + (l - 1) * B, Sum = 0, r = -1;
    long long al = l, ar = 1e9;
    while (al <= ar) {
      long long mid = (al + ar) / 2,
                ss = (Sl + (mid - 1) * B + A) * (mid - l + 1) / 2;
      if (ss <= m * t && (mid - 1) * B + A <= t)
        r = mid, al = mid + 1;
      else
        ar = mid - 1;
    }
    cout << r << endl;
  }
  return 0;
}
