#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A, B, n;
  scanf("%I64d%I64d%I64d", &A, &B, &n);
  long long l, t, m;
  long long left, right, mid;
  while (n--) {
    scanf("%I64d%I64d%I64d", &l, &t, &m);
    if ((A + (l - 1) * B) > t)
      printf("-1\n");
    else {
      left = l;
      right = 1 + (t - A) / B;
      while (left <= right) {
        mid = (left + right) / 2;
        long long head = A + (l - 1) * B;
        long long tail = A + (mid - 1) * B;
        long long sum = (head + tail) * (mid - l + 1) / 2;
        if (sum <= t * m)
          left = mid + 1;
        else
          right = mid - 1;
      }
      printf("%I64d\n", left - 1);
    }
  }
  return 0;
}
