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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class d {
    static BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
    // static Scanner s=new Scanner(System.in);
    public static void main(String[] args) throws IOException {
        StringBuilder sb = new StringBuilder();
         String[] s1=s();
     int a=i(s1[0]);int b=i(s1[1]);int n=i(s1[2]);
     while(n-->0){
         String[] s2=s();
         int l=i(s2[0]);int t=i(s2[1]);int m=i(s2[2]);
         long sum=((long)l-1L)*(2L*(long)a+((long)l-2L)*(long)b)/2L;
       //  System.out.println(sum);
         int low=l;int high=1000000;
         int ans=-1;
         long have=t*m;
         while(low<=high){
             int mid=(low+high)/2;
             have=((long)(m)*(long)t);
             long x=((long)mid)*(2L*(long)a+((long)mid-1L)*(long)b)/2L-(long)sum;

             if(x<=have&&t>=(long)a+(long)(mid-1)*(long)b){
                 //System.out.println(x+" "+have+" "+mid);
                 ans=mid;
                 low=mid+1;
             }else{
                 high=mid-1;
             }
         }
         sb.append(ans+"\n");
     }
        System.out.println(sb.toString());
    }
static int count=0;static long ans=1;static int mod;
    static HashMap<Integer,Integer> h;
    static void dfs(ArrayList<Integer>[] adj,int[] vis,int i,int flag,long[] pot){
       h.put(i,flag);
       if(adj[i]==null) return;
       for(Integer j:adj[i]){
           if(h.containsKey(j)){
               count+=flag-h.get(j)+1;
               ans=(ans*(pot[flag-h.get(j)+1]-2))%mod;
           }
           else if(vis[j]!=0){
               continue;
           }
           else{
               dfs(adj,vis,j,flag+1,pot);
           }
       }
    }
    static void bfs(char[][] a,int i,int j,int n,int m){

    }

    static long gcd(long a, long b) {

        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    static String[] s() throws IOException {

        return s.readLine().trim().split("\\s+");
    }

    static int i(String ss) {
        return Integer.parseInt(ss);
    }
    static long l(String ss) {
        return Long.parseLong(ss);
    }
}

class Student12 {
    int  l;long r;
    public Student12(int l, long r) {
        this.l = l;
        this.r = r;
    }

    public String toString()
    {
        return this.l+" ";
    }
}
class Sortbyroll12 implements Comparator<Student12> {

    public int compare(Student12 a, Student12 b){
        if(b.r<a.r) return -1;
        else if(b.r==a.r) return 0;
        return 1;
//        return b.r- a.r;
//        return (int) a.l-(int) b.l;
     /*   if(a.r<b.r) return -1;
        else if(a.r==b.r){
            if(a.r==b.r){
                return 0;
            }
            if(a.r<b.r) return -1;
            return 1;}
        return 1;  */}
}