#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long a, b, n, l, t, m;
long long sum(long long x) { return x * (x + 1) / 2; }
int main() {
  cin >> a >> b >> n;
  while (n--) {
    cin >> l >> t >> m;
    long long hi = (l - 1) * b + a;
    if (hi > t)
      cout << -1 << endl;
    else {
      long long le = 1, ri = 1e12;
      while (le < ri) {
        long long mid = (le + ri + 1) / 2;
        long long hi = (mid - 1) * b + a;
        long long x = (sum(mid - 1) - sum(l - 2)) * b + (mid - l + 1) * a;
        long long k = m * t;
        if (x > k || hi > t)
          ri = mid - 1;
        else
          le = mid;
      }
      cout << le << endl;
    }
  }
}
