#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 22, INF = 1e7 + 2;
long long n, A, B, L, t, m, x, low, high, mid, s;
bool check(long long ans) {
  if (s + (ans - 1) * B > t) return false;
  x = A * ans +
      B * (((ans + L - 1) * (ans + L - 1 - 1) / 2) - ((L - 1) * (L - 2) / 2));
  if (x <= t * m)
    return true;
  else
    return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> A >> B >> n;
  for (int j = 1; j <= n; j++) {
    cin >> L >> t >> m;
    s = A + (L - 1) * B;
    if (s > t)
      cout << -1 << endl;
    else {
      low = 1, high = INF;
      while (high >= low) {
        mid = (low + high) / 2;
        if (check(mid))
          low = mid + 1;
        else
          high = mid - 1;
      }
      cout << high + L - 1 << endl;
    }
  }
  return 0;
}
