#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10240000,10240000")
using namespace std;
const int dx[8] = {0, 0, -1, 1};
const int dy[8] = {-1, 1, 0, 0};
const int maxn = 4e5 + 7;
const int maxm = 1e3 + 7;
const int maxv = 1e7 + 7;
const int max_val = 1e6 + 7;
const int MD = 22;
const int INF = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-10;
template <class T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <class T>
void ReadInt(T &x) {
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
}
template <class T>
void WriteInt(T i) {
  if (i < 0) {
    putchar('-');
    i = -i;
  }
  int p = 0;
  static int b[20];
  if (i == 0)
    b[p++] = 0;
  else
    while (i) {
      b[p++] = i % 10;
      i /= 10;
    }
  for (int j = p - 1; j >= 0; j--) putchar('0' + b[j]);
}
template <class T>
bool max_update(T &a, const T &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool min_update(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
T condition(bool f, T a, T b) {
  return f ? a : b;
}
template <class T>
void copy_arr(T a[], T b[], int n) {
  for (int i = 0; i < (n); i++) a[i] = b[i];
}
int make_id(int x, int y, int n) { return x * n + y; }
long long l, m, t, A, B;
bool chk(int r) {
  long long sum = (A + (l - 1) * B + A + (r - 1) * B) * (r - l + 1) / 2,
            maxh = A + (r - 1) * B;
  return sum <= m * t && maxh <= t;
}
int main() {
  int n;
  while (cin >> A >> B >> n) {
    for (int i = 0; i < (n); i++) {
      ReadInt(l);
      ReadInt(t);
      ReadInt(m);
      int L = l, R = 1e7;
      while (L <= R) {
        int M = (L + R + 1) >> 1;
        if (chk(M))
          L = M;
        else
          R = M - 1;
        if (L == M && M == R) break;
      }
      if (L == R)
        WriteInt(L);
      else
        WriteInt(-1);
      putchar('\n');
    }
  }
  return 0;
}
