#include <bits/stdc++.h>
using namespace std;
long long a, b, n, l, t, m;
bool OK(long long mid) {
  long long w, e;
  w = a + (mid - 1) * b;
  e = a * (mid - l + 1) + b * (mid * (mid - 1) / 2 - (l - 1) * (l - 2) / 2);
  if (t >= w && m * t >= e)
    return true;
  else
    return false;
}
int main() {
  long long lb, ub, mid;
  scanf("%I64d%I64d%I64d", &a, &b, &n);
  while (n--) {
    scanf("%I64d%I64d%I64d", &l, &t, &m);
    lb = l - 1, ub = 1000000000000;
    while (ub - lb > 1) {
      mid = (lb + ub) / 2;
      if (OK(mid))
        lb = mid;
      else
        ub = mid;
    }
    if (lb < l)
      printf("-1\n");
    else
      printf("%I64d\n", lb);
  }
  return 0;
}
