#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, q, l, t, m, i;
  long long left, right, mid, total;
  scanf("%d%d%d", &a, &b, &q);
  for (i = 0; i < q; i++) {
    scanf("%d%d%d", &l, &t, &m);
    left = l - 1;
    right = t + 1;
    while (right - left > 1) {
      mid = (left + right) / 2;
      if ((mid - 1) * b + a > t) {
        right = mid;
        continue;
      }
      total =
          ((mid - 1) * b + a + (long long)(l - 1) * b + a) * (mid - l + 1) / 2;
      if (total > (long long)m * t) {
        right = mid;
        continue;
      }
      left = mid;
    }
    if (left == l - 1) {
      printf("-1\n");
    } else
      printf("%d\n", (int)left);
  }
  return 0;
}
