#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long a, b, n, l, t, m;
  cin >> a >> b >> n;
  while (n--) {
    cin >> l >> t >> m;
    if (a + b * (l - 1) > t) {
      cout << "-1" << endl;
      continue;
    } else {
      long long L = l, R = (t - a + b) / b;
      while (L <= R) {
        long long mid = L + (R - L) / 2;
        if ((2 * a + (l + mid - 2) * b) * (mid - l + 1) > 2 * t * m)
          R = mid - 1;
        else
          L = mid + 1;
      }
      cout << R << endl;
    }
  }
  return 0;
}
