#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbgarr(T *a, int s, int t) {
  for (int i = s; i <= t; i++) cerr << a[i] << ' ';
  cerr << endl;
}
int main() {
  int a, b, n;
  scanf("%d%d%d", &a, &b, &n);
  for (int i = 0; i < n; i++) {
    long long l, t, m;
    scanf("%I64d%I64d%I64d", &l, &t, &m);
    long long sl = a + (l - 1) * b;
    if (sl > t)
      printf("-1\n");
    else {
      long long ll = l, lr = (t - a) / b + 1, mid;
      while (ll <= lr) {
        long long mid = (ll + lr) / 2;
        if (((a + (mid - 1) * b) + (a + (l - 1) * b)) * (mid - l + 1) / 2 <=
            t * m)
          ll = mid + 1;
        else
          lr = mid - 1;
      }
      printf("%d\n", ll - 1);
    }
  }
}
