#include <bits/stdc++.h>
const char en = '\n';
using namespace std;
long long hod(long long pos, long long a, long long b) {
  return a + b * (pos - 1);
}
long long sum(long long z, long long k, long long a, long long b) {
  return ((hod(k, a, b) + hod(z, a, b)) * (k - z + 1)) / 2;
}
int main() {
  ios::sync_with_stdio(false);
  int a, b, n;
  cin >> a >> b >> n;
  for (int i = 0; i < n; i++) {
    long long lll, t, m;
    cin >> lll >> t >> m;
    long long r = 10000000;
    long long l = lll;
    while (l < r - 1) {
      long long mid = (l + r) / 2;
      if (sum(lll, mid, a, b) > t * m || hod(mid, a, b) > t)
        r = mid;
      else
        l = mid;
    }
    if (sum(lll, l, a, b) > t * m || hod(l, a, b) > t)
      cout << "-1" << en;
    else
      cout << l << en;
  }
}
