#include <bits/stdc++.h>
using namespace std;
const int nmax = 1000010;
const int mod = 1000000007;
vector<int> v;
long long kar[nmax];
long long sum[nmax];
int main() {
  ios_base::sync_with_stdio(0);
  long long A, B;
  long long n;
  cin >> A >> B;
  cin >> n;
  for (int i = 1; i < nmax; ++i) kar[i] = A + (i - 1) * B;
  for (int i = 1; i < nmax; ++i) sum[i] = sum[i - 1] + kar[i];
  while (n) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long lft = upper_bound(kar, kar + nmax - 1, t) - kar - 1;
    long long rgt =
        upper_bound(sum, sum + nmax - 1, sum[l - 1] + t * m) - sum - 1;
    long long dop = min(rgt, lft);
    if (dop >= l)
      cout << dop << endl;
    else
      cout << -1 << endl;
    n--;
  }
  return 0;
}
