Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.

<image>

Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.

For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.

Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.

Input

The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).

Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.

Output

For each query, print its answer in a single line.

Examples

Input

2 1 4
1 5 3
3 3 10
7 10 2
6 4 8


Output

4
-1
8
-1


Input

1 5 2
1 5 10
2 7 4


Output

1
2
#include <bits/stdc++.h>
using namespace std;
const long double Pi = 3.141592653;
const long long mod = 1e9 + 9;
vector<long long> primes;
long long modoinv(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) {
    return 0;
  }
  while (a > 1) {
    long long t, q = a / m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) {
    x += m0;
  }
  return x;
}
class Graph {
  map<long long, vector<long long>> ma;

 public:
  void addedge(long long n, long long m) {
    ma[n].push_back(m);
    ma[m].push_back(n);
  }
};
class Node {
 public:
  char data;
  unordered_map<char, Node*> children;
  bool terminal;
  Node(char d) {
    data = d;
    terminal = false;
  }
};
class Trie {
 public:
  Node* root;
  long long cnt;
  Trie() {
    root = new Node('\0');
    cnt = 0;
  }
  void insert(char* w) {
    Node* temp = root;
    for (long long i = 0; w[i] != '\0'; i++) {
      char ch = w[i];
      if (temp->children.count(ch)) {
        temp = temp->children[ch];
      } else {
        Node* n = new Node(ch);
        temp->children[ch] = n;
        temp = n;
      }
    }
    temp->terminal = true;
  }
  bool find(string w) {
    Node* temp = root;
    for (long long i = 0; w[i] != '\0'; i++) {
      char ch = w[i];
      if (temp->children.count(ch) == 0)
        return false;
      else {
        temp = temp->children[ch];
      }
    }
    return temp->terminal;
  }
};
vector<long long> primeFactors(long long n) {
  vector<long long> ans;
  long long cur = 1;
  ans.push_back(1);
  while (n % 2 == 0) {
    cur = cur * 2;
    ans.push_back(cur);
    n = n / 2;
  }
  for (long long i = 3; i * i <= (n); i = i + 2) {
    while (n % i == 0) {
      cur = cur * i;
      ans.push_back(cur);
      n = n / i;
    }
  }
  if (n > 2) ans.push_back(cur * n);
  return ans;
}
void sieve(long long p) {
  vector<bool> mark(p, 1);
  for (long long i = 3; i < p; i += 2) {
    if (mark[i] == 1) {
      for (long long j = i * i; j < p; j += 2 * i) {
        mark[j] = 0;
      }
    }
  }
  primes.push_back(2);
  for (long long i = 3; i < p; i += 2) {
    if (mark[i]) primes.push_back(i);
  }
}
long long mod_exp(long long x, long long n, long long m) {
  if (n == 0) return 1 % m;
  long long a = mod_exp(x, n / 2, m);
  if (n % 2 == 0)
    return (a * a) % m;
  else
    return (x * a * a) % m;
}
bool isPrime(long long n) {
  if (n == 1) return 0;
  if (n == 2) return 1;
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
bool check(long long a, long long d, long long n, long long s) {
  if (s >= (((2 * a + (n - 1) * d) * n) / 2)) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a1, b1, n;
  cin >> a1 >> b1 >> n;
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long a = a1 + (l - 1) * b1;
    long long left = 1, right = 1 + ((t - a) / b1), mid, ans;
    if (right < left) {
      cout << -1 << endl;
      continue;
    }
    while (right >= left) {
      mid = (right + left) / 2;
      if (check(a, b1, mid, t * m)) {
        ans = mid;
        left = mid + 1;
      } else
        right = mid - 1;
    }
    cout << ans + l - 1 << endl;
  }
}
