#include <bits/stdc++.h>
using namespace std;
long long lowS(long long a, long long b, long long s) {
  long long t = 2 * a - b;
  long long low = 0, high = 1100000;
  while (low + 1 < high) {
    long long mid = (low + high) / 2;
    long long tmp = mid * (mid * b + t);
    if (tmp > s)
      high = mid;
    else
      low = mid;
  }
  return low - 1;
}
long long lowA(long long a, long long b, long long s) { return (s - a) / b; }
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long e = a + (l - 1) * b;
    if (t < e)
      cout << "-1" << endl;
    else {
      long long ls = lowS(e, b, 2 * m * t);
      long long la = lowA(e, b, t);
      cout << l + min(ls, la) << endl;
    }
  }
  return 0;
}
