#include <bits/stdc++.h>
using namespace std;
long long int a, b, n, l, t, m;
bool valid(long long int r) {
  return (t >= (a + (r - 1) * b)) &&
         (m >= r - l + 1 ||
          m * t >= a * (r - l + 1) + b * (r * (r - 1) - (l - 2) * (l - 1)) / 2);
}
long long int binarySearch() {
  long long int s = l, e = 1000002, v = s + (e - s) / 2;
  while (s <= e) {
    if (valid(v) && !valid(v + 1)) return v;
    if (valid(v)) {
      s = v + 1;
      v = s + (e - s) / 2;
    } else {
      e = v - 1;
      v = s + (e - s) / 2;
    }
  }
  return -1;
}
int main() {
  cin >> a >> b >> n;
  while (n--) cin >> l >> t >> m, cout << binarySearch() << endl;
}
