#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int a, b, n;
  cin >> a >> b >> n;
  while (n--) {
    long long int l, t, m;
    cin >> l >> t >> m;
    if (t < a + (l - 1) * b) {
      cout << -1 << "\n";
    } else {
      long long int ans;
      long long int lo = l, hi = (t - a) / b + 1;
      for (long long int i = 0; i < 80; i++) {
        long long int mid = (lo + hi) / 2;
        long long int x = a * (mid - l + 1) +
                          ((mid * (mid - 1) / 2) - ((l - 1) * (l - 2) / 2)) * b;
        if (x <= m * t) {
          ans = mid;
          lo = mid + 1;
        } else
          hi = mid - 1;
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
