#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int MOD = 1000000007;
long long get(long long A, long long B, long long n, long long m) {
  long long ans = A + (n - 1) * B;
  long long s = n * (A + (A + (n - 1) * B)) / 2;
  ans = max(ans, (s + m - 1) / m);
  return ans;
}
int main() {
  long long A, B, n;
  cin >> A >> B >> n;
  while (n--) {
    long long l, t, m;
    scanf("%I64d %I64d %I64d", &l, &t, &m);
    long long low = l, high = 1000000;
    while (low < high) {
      long long mid = (low + high) / 2 + 1;
      if (get(A + (l - 1) * B, B, mid - l + 1, m) <= t)
        low = mid;
      else
        high = mid - 1;
    }
    if (get(A + (l - 1) * B, B, high - l + 1, m) > t) high = -1;
    cout << high << endl;
  }
}
