#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, n;
  scanf("%d %d %d", &a, &b, &n);
  while (n--) {
    int l, t, m;
    scanf("%d %d %d", &l, &t, &m);
    int answer = -1;
    int low = l, high = 3e6;
    long long vf = a + (l - 1LL) * b;
    while (low <= high) {
      int mid = (low + high) / 2;
      bool ok = true;
      long long vt = a + (mid - 1LL) * b;
      long long sum = (vf + vt) * (mid - l + 1) / 2;
      if (vt > t) {
        ok = false;
      }
      int k = min(mid - l + 1, m);
      if (sum > 1LL * t * k) {
        ok = false;
      }
      if (ok) {
        answer = mid;
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
    printf("%d\n", answer);
  }
}
