#include <bits/stdc++.h>
using namespace std;
long long a, b, t, m;
int n, l, q;
int main() {
  scanf("%lld%lld%d", &a, &b, &q);
  while (q--) {
    scanf("%d%lld%lld", &l, &t, &m);
    long long L = a + (l - 1) * b;
    int lo = 1, hi = 1000000, len = -1;
    while (lo <= hi) {
      int mid = (lo + hi) >> 1;
      int pos = l + mid - 1;
      long long R = a + (pos - 1) * b;
      long long sum = (L + R) * mid / 2;
      if (sum <= m * t && R <= t) {
        lo = mid + 1;
        len = pos;
      } else
        hi = mid - 1;
    }
    printf("%d\n", len);
  }
}
