#include <bits/stdc++.h>
using namespace std;
long long a, b, n, l, t, m;
bool okay(long long idx) {
  if ((idx - 1) * b + a > t) {
    return false;
  }
  long long num = idx - l + 1, firstTerm = a + (l - 1) * b;
  long long sum = num * (2 * firstTerm + (num - 1) * b) / 2;
  if (sum > t * m) {
    return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> a >> b >> n;
  for (long long i = 0; i < n; i++) {
    cin >> l >> t >> m;
    long long low = l, high = 1e9;
    if (not okay(l)) {
      cout << "-1\n";
      continue;
    }
    while (high - low > 1) {
      long long mid = (high + low) / 2;
      if (not okay(mid)) {
        high = mid - 1;
      } else {
        low = mid;
      }
    }
    if (okay(high)) {
      cout << high << "\n";
      continue;
    }
    cout << low << "\n";
  }
}
