#include <bits/stdc++.h>
using namespace std;
const inline int __GET_INT() {
  int ret;
  scanf("%d", &ret);
  return ret;
}
int main() {
  long long A = __GET_INT(), B = __GET_INT(), n = __GET_INT();
  for (int i = 0; i < n; ++i) {
    long long l = __GET_INT(), t = __GET_INT(), m = __GET_INT();
    long long first = B * (l - 1) + A;
    if (first > t) {
      puts("-1");
    } else {
      int r = -1;
      long long low = 1, high = 1000000, mid;
      while (low <= high) {
        mid = (low + high) >> 1;
        long long val = ((mid * (mid - 1)) / 2) * B + mid * first;
        long long second = B * (l + mid - 2) + A;
        if (second > t || val > (t * m)) {
          high = mid - 1;
        } else {
          low = mid + 1;
          r = l + mid - 1;
        }
      }
      printf("%d\n", r);
    }
  }
  return 0;
}
