#include <bits/stdc++.h>
using namespace std;
long long int binpowmod(long long int a, long long int b, long long int m) {
  a %= m;
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long int binpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return binpowmod(n, p - 2, p);
}
vector<vector<long long int>> adj1, adj2;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t, m, n, i, f = 0, j, ans = 0, l, r;
  long long int a, b, x, t1;
  cin >> a >> b >> n;
  for (i = 0; i < n; ++i) {
    cin >> l >> t >> m;
    long long int l1, r1, mid;
    t1 = a + (l - 1) * b;
    if (t1 > t) {
      cout << -1 << endl;
      continue;
    }
    x = (t - a) / b + 1;
    l1 = l, r1 = x;
    while (l1 <= r1) {
      mid = l1 + (r1 - l1) / 2;
      t1 =
          a * (mid - l + 1) + b * (((mid - 1) * (mid) - (l - 1) * (l - 2)) / 2);
      if (t1 <= t * m) {
        r = mid;
        l1 = mid + 1;
      } else {
        r1 = mid - 1;
      }
    }
    cout << r << endl;
  }
  return 0;
}
