#include <bits/stdc++.h>
using namespace std;
long long SUM[1000005];
int binarySearch(int left, int right, long long x) {
  int middle = (left + right) / 2;
  if (left == right) {
    if (SUM[left] > x) return -1;
    return left;
  }
  if (left + 1 == right) {
    if (SUM[right] <= x) return right;
    return left;
  }
  if (SUM[middle] <= x)
    return binarySearch(middle, right, x);
  else
    return binarySearch(left, middle - 1, x);
}
int main() {
  int A, B, N;
  cin >> A >> B >> N;
  SUM[0] = 0;
  for (int i = 1; i < 1000005; i++) {
    long long x = A + (long long)B * (i - 1);
    SUM[i] = (long long)SUM[i - 1] + x;
  }
  for (int i = 1; i <= N; i++) {
    int L, R, T, M;
    cin >> L >> T >> M;
    R = (T - A) / B + 1;
    if (R < L)
      cout << "-1\n";
    else
      cout << binarySearch(L, R, (long long)T * M + SUM[L - 1]) << "\n";
  }
}
