#include <bits/stdc++.h>
long long a1[1000005];
long long a2[1000005], l, t, m;
int check(long long input) {
  long long temp;
  if (a1[input] > t) {
    return 0;
  } else {
    temp = a2[input] - a2[l - 1];
    if (temp <= (t * m)) {
      return 1;
    } else {
      return 0;
    }
  }
}
void binary_search(long long int l) {
  long long lower_limit = l, temp;
  long long higher_limit = 1000000;
  long long mid_point;
  while (lower_limit < higher_limit) {
    mid_point = (lower_limit + higher_limit + 1) / 2;
    if (a1[mid_point] > t) {
      higher_limit = mid_point - 1;
    } else {
      temp = a2[mid_point] - a2[l - 1];
      if (temp <= (t * m)) {
        lower_limit = mid_point;
      } else {
        higher_limit = mid_point - 1;
      }
    }
  }
  if (check(lower_limit) == 1) {
    printf("%I64d\n", lower_limit);
  } else {
    printf("-1\n");
  }
}
int main() {
  long long a, b, n, i;
  scanf("%I64d %I64d %I64d", &a, &b, &n);
  a2[0] = 0;
  for (i = 1; i < 1000005; i++) {
    a1[i] = a + b * (i - 1);
    a2[i] = a1[i] + a2[i - 1];
  }
  for (i = 0; i < n; i++) {
    scanf("%I64d %I64d %I64d", &l, &t, &m);
    binary_search(l);
  }
  return 0;
}
