#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A, B, n;
  cin >> A >> B >> n;
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long lo = l;
    long long hi = l + t + 5;
    long long md;
    while (lo <= hi) {
      md = (lo + hi) / 2;
      long long mr = A + (md - 1) * B;
      long long sm =
          (md - l + 1) * A + B * (md * (md - 1) / 2 - (l - 1) * (l - 2) / 2);
      if (mr <= t && sm <= t * m) {
        lo = md + 1;
      } else
        hi = md - 1;
    }
    if (hi < l)
      cout << -1 << endl;
    else
      cout << hi << endl;
  }
}
