#include <bits/stdc++.h>
using namespace std;
double PI = 4.00 * (atan(1));
long long int summation(long long int a, long long int b, long long int index) {
  long long int ans = 0;
  ans += (a * index);
  ans += (index * (index - 1) * b / 2);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int a, b, query;
  long long int left, rep, len;
  cin >> a >> b >> query;
  while (query--) {
    cin >> left >> rep >> len;
    long long int val1 = a + (left - 1) * b;
    if (val1 > rep) {
      cout << "-1" << endl;
      continue;
    }
    long long int low = left;
    long long int store = summation(a, b, left - 1);
    long long int high = 1000000009;
    long long int ans, mid, max_value;
    while (low <= high) {
      mid = (low + high) / 2;
      val1 = summation(a, b, mid);
      val1 -= store;
      max_value = a + (mid - 1) * b;
      if (val1 <= (rep * len) && max_value <= rep) {
        ans = mid;
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
