#include <bits/stdc++.h>
using namespace std;
void read(int a = 0) {
  freopen("in", "r", stdin);
  if (a) freopen("output.txt", "w", stdout);
}
long long argo(long long a, long long b) {
  a = max(a, (long long)1);
  return (b - a + 1) * (b + a) / 2;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long a, b, n;
  cin >> a >> b >> n;
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long length = a + b * (l - 1);
    if (length > t) {
      cout << -1 << endl;
      continue;
    }
    long long lo = l, hi = 1000000007;
    while (lo < hi) {
      long long mid = lo + hi + 1;
      mid /= 2;
      long long sum = (mid - l + 1) * a + b * argo(l - 1, mid - 1);
      long long mx = a + b * (mid - 1);
      if (mx <= t && sum <= m * t)
        lo = mid;
      else
        hi = mid - 1;
    }
    cout << lo << endl;
  }
}
