#include <bits/stdc++.h>
using namespace std;
long long m;
long long l, t;
long long a, b, n;
int main() {
  cin >> a >> b >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> l >> t >> m;
    if (a + b * (l - 1) > t) {
      cout << -1 << endl;
    } else {
      long long left = l;
      long long right = (t - a) / b + 1;
      while (right >= left) {
        long long mid = (left + right) / 2;
        long long temp = (a * (mid - l + 1) +
                          b * (mid * (mid - 1) / 2 - (l - 1) * (l - 2) / 2));
        if ((a + b * (mid - 1)) <= t && temp <= m * t) {
          left = mid + 1;
        } else
          right = mid - 1;
      }
      cout << left - 1 << endl;
    }
  }
}
