#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A, B, n;
  cin.sync_with_stdio(false);
  cin >> A >> B >> n;
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    if (A + (l - 1) * B > t) {
      cout << -1 << endl;
      continue;
    }
    long long right = (t - A) / B + 10;
    long long left = l;
    while (left < right) {
      long long mid = (left + right + 1) / 2;
      long long width = mid - l + 1;
      long long maximum = A + (mid - 1) * B;
      long long minimum = A + (l - 1) * B;
      long long sum = (maximum + minimum) * width / 2;
      if (maximum > t) {
        right = mid - 1;
        continue;
      }
      if (width <= m) {
        left = mid;
        continue;
      }
      long long times = (sum - 1) / m + 1;
      if (times > t) {
        right = mid - 1;
      } else {
        left = mid;
      }
    }
    cout << left << endl;
  }
}
