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