#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5;
const long long mod = 1e9 + 7;
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  while (n-- > 0) {
    long long st, l, r, t, m;
    cin >> l >> t >> m;
    l -= 1;
    r = t + 1;
    st = l;
    long long mx = t * m;
    long long val = a + b * l;
    while (l < r) {
      long long mid = (l + r) / 2;
      long long add = a + b * mid;
      long long tot = ((val + add) * (mid - st + 1)) / 2;
      if (add > t || tot > mx)
        r = mid;
      else
        l = mid + 1;
    }
    cout << (r <= st ? -1 : r) << "\n";
  }
}
