#include <bits/stdc++.h>
using namespace std;
long long int A, B, n, t, m, l;
long long tab[1000100];
long long suma[1000100];
void przygotuj() {
  for (int i = 1; i < 1000100; i++) {
    tab[i] = A + B * (i - 1);
    suma[i] = suma[i - 1] + tab[i];
  }
}
int znajdz() {
  int p = l, k = 1000100, mid;
  if (tab[p] > t) return -1;
  while (p + 1 < k) {
    mid = (p + k) / 2;
    if (tab[mid] <= t && suma[mid] - suma[l - 1] <= t * m) {
      p = mid;
    } else
      k = mid;
  }
  return p;
}
int main() {
  cout.sync_with_stdio(0);
  cin >> A >> B >> n;
  przygotuj();
  while (n--) {
    cin >> l >> t >> m;
    int odp = znajdz();
    cout << odp << "\n";
  }
  return 0;
}
