#include <bits/stdc++.h>
using namespace std;
long long mt;
int a, b;
bool valid(long long x, long long l) {
  long long temp;
  temp = a * (x - l + 1);
  temp += b * ((x - 1) * x / 2 - (l - 2) * (l - 1) / 2);
  if (temp <= mt) return true;
  return false;
}
int main(void) {
  int n, l, t, m, lo, hi;
  long long temp;
  scanf("%d %d %d", &a, &b, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &l, &t, &m);
    mt = (long long)m * t;
    temp = a + (long long)(l - 1) * b;
    if (temp > t) {
      printf("-1\n");
      continue;
    }
    temp = (t - a) / b + 1;
    hi = temp;
    lo = l;
    if (valid(hi, l))
      printf("%d\n", temp);
    else {
      while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        if (valid(mid, l))
          lo = mid;
        else
          hi = mid;
      }
      printf("%d\n", lo);
    }
  }
  return 0;
}
