#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  int n;
  cin >> a >> b >> n;
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long levo = 0, desno = 100000001LL;
    long long k = l;
    l = a + (l - 1) * b;
    if (l > t) {
      cout << -1 << endl;
      continue;
    }
    long long rez = -1;
    while (levo <= desno) {
      long long mid = (levo + desno) / 2LL;
      if ((l + mid * b) > t ||
          ((mid * (mid + 1)) / 2LL) * b + (mid + 1) * l > t * m)
        desno = mid - 1;
      else
        rez = mid, levo = mid + 1;
    }
    if (rez == -1)
      cout << -1 << endl;
    else
      cout << k + rez << endl;
  }
  return 0;
}
