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

//package acc;
//import java.math.BigInteger;
//import java.util.List;
//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		//StreamTokenizer st = new StreamTokenizer(br);
                //OutputStream outputStream = System.out;
                //PrintWriter out = new PrintWriter(outputStream);
//st.nextToken();
//(int) st.nval;
             
import static java.util.Collections.reverseOrder;
import java.util.ArrayList;
//import java.io.OutputStream;
//import java.io.PrintWriter;
import java.util.Date;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import static java.util.Comparator.comparing;
   public  class ACC {
      static int arr[]=new int [101000];
       static List <Integer> prime=new ArrayList<>();
//***********functions************//      
       static void sieve(){
           arr[0]=1;
           arr[1]=1;
           for(int i=2;i<101000;i++){
               if(arr[i]==0){
                   for(int j=2*i;j<101000;j+=i)
                       arr[j]=1;
               }
           }
           for(int i=2;i<101000;i++){
               if(arr[i]==0) prime.add(i);
           }
       }
       
       static int BS (int key){
           int start=0;
           int end=prime.size()-1;
           while(end>start+1){
               int mid=(start+end)/2;
               if(prime.get(mid)<key) start=mid+1;
               else end=mid;
           }
           int up=Math.abs(prime.get(end)-key);
           int dow=Math.abs(key-prime.get(start));
           if(prime.get(start)>key) return dow;
           return up;
           
       }
         
       
//************Main*****************//         
         public static void main(String[] args) throws NumberFormatException,
			IOException {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		StreamTokenizer st = new StreamTokenizer(br);
                //Scanner in=new Scanner (System.in);
               
                      st.nextToken();
                   long a=   (long) st.nval;
                      st.nextToken();
                      long b=(long) st.nval;
                   //int b=in.nextInt();
                     st.nextToken();
                     int n=(int) st.nval;
                long arr1[]=new long[1000001];
                for(int i=1;i<1000001;i++){
                    
                
                    arr1[i]=a+(i-1)*b;
                    arr1[i]+=arr1[i-1];
                }
                for(int i=0;i<n;i++){
                    st.nextToken();
                    long l=(int) st.nval;
                    st.nextToken();
                    long t=(int) st.nval;
                    st.nextToken();
                    long m=(int) st.nval;
                    int sta=0;
                    int end=1000000;
                   
                    /*while(sta<end){
                        int mid=sta+(end-sta+1)/2;
                        if(arr1[mid]>t){
                            end=mid-1;
                        } 
                        else sta=mid;
                    }*/
                   // if(sta>=l) {
                        long sum1=(l-1)*(a-b)+b*((l-1)*l/2);
                        long le=0;
                        long ri=1000000;
                        while(le<ri){
                            long mid=le+(ri-le+1)/2;
                               long sum=mid*(a-b)+b*(mid*(mid+1)/2);
                               sum-=sum1;
                               if(sum>t*m ||t<(a+(mid-1)*b)) ri=mid-1;
                               else le=mid;
                        }
                        if(le>=l) System.out.println(le);
                        else System.out.println("-1");
                    //}
                    //else System.out.println("-1");
                }
         
         
         }
         
         
public static class Pair< L,R> {
    private L l;
    private R r;
    public Pair(L l, R r){
        this.l = l;
        this.r = r;
    }
    public  L getL(){ return l; }
    public R getR(){ return r; }
    public void setL(L l){ this.l = l; }
    public void setR(R r){ this.r = r; }
}
    public static int next_permutation(int[] array) {
 int i, j;
 // Find the largest index k such that a[k] < a[k + 1]. If no such index
 // exists, the permutation is the last permutation.
 for (i = array.length - 2; i >= 0; i--) {
     if (array[i] < array[i + 1])
  break;
 }
 if (i < 0) {
     //System.out.println("End");
     return 0;
 }

 // Find the largest index l such that a[k] < a[l]. Since k + 1 is such
 // an index, l is well defined and satisfies k < l.
 for (j = array.length - 1; j > i; j--) {
     if (array[j] > array[i])
  break;
 }

 // Swap a[k] with a[l].
 swap(array, i++, j);

 // Reverse the sequence from a[k + 1] up to and including the final
 // element a[n].
 for (j = array.length - 1; j > i; i++, j--) {
     swap(array, i, j);
 }
 return 1;
    }

    public static void swap(int[] array, int x, int y) {
 array[x] ^= array[y];
 array[y] ^= array[x];
 array[x] ^= array[y];
    }
    
    
}
