import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class e
{
    public static void print(String str,long val){
        System.out.println(str+"  "+val);
    }

    public long gcd(long a, long b) {
        if (b==0L) return a;
        return gcd(b,a%b);
    }

    public static void debug(long[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(int[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(arr[i]);
        }
    }

    public static void print(int[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }

    public static void print(Object[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(long[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
        public FastReader(String path) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(path));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args)
    {
        FastReader s=new FastReader();
        int t = s.nextInt();
        for(int tt=0;tt<t;tt++){
            int n = s.nextInt();
            int k = s.nextInt();
            if(k%3!=0){
                if(n%3==0){
                    System.out.println("Bob");
                }
                else {
                    System.out.println("Alice");
                }
            }
            else {
                int np = n%(k+1);
                if(np%3==0 && np!=k){
                    System.out.println("Bob");
                }
                else {
                    System.out.println("Alice");
                }
            }
        }

    }

//    OutputStream out = new BufferedOutputStream( System.out );
//        for(int i=1;i<n;i++){
//              out.write((arr[i]+" ").getBytes());
//         }
//        out.flush();
//  long start_time = System.currentTimeMillis();
//  long end_time = System.currentTimeMillis();
//  System.out.println((end_time - start_time) + "ms");

}


import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class e
{
    public static void print(String str,int val){
        System.out.println(str+"  "+val);
    }

    public long gcd(long a, long b) {
        if (b==0L) return a;
        return gcd(b,a%b);
    }

    public static void debug(long[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(int[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(arr[i]);
        }
    }

    public static void print(int[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(long[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
        public FastReader(String path) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(path));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args)
    {
        FastReader s=new FastReader();
        int t = s.nextInt();
        for(int tt=0;tt<t;tt++){
            int n = s.nextInt();
            int k= s.nextInt();
            if((n+k)%2==1){
                System.out.println("Bob");
            }
            else{
                System.out.println("Alice");
            }
        }

    }

//    OutputStream out = new BufferedOutputStream( System.out );
//        for(int i=1;i<n;i++){
//              out.write((arr[i]+" ").getBytes());
//         }
//        out.flush();
//  long start_time = System.currentTimeMillis();
//  long end_time = System.currentTimeMillis();
//  System.out.println((end_time - start_time) + "ms");

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;
import java.util.Random;
import java.util.StringTokenizer;

public class Solution{

	public static void main(String[] args) {

		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		int tt = fs.nextInt();
		while(tt-->0) {

			long n = fs.nextLong();
			long k = fs.nextLong();

			boolean bool = true;

			if(k%3!=0) {
				if(n%3==0) {
					bool = false;
				}
			}

			else {
				long num = n%(k+1);
				if(num%3==0 && num!=k) {
					bool = false;
				}
			}

			out.println(bool?"Alice":"Bob");

		}

		out.close();

	}

	static final Random random=new Random();

	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}

	static class FastScanner{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		public String next(){
			while(!st.hasMoreElements()){
				try{
					st = new StringTokenizer(br.readLine());
				} catch(IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt(){
			return Integer.parseInt(next());
		}

		public int[] readArray(int n){
			int[] a = new int[n];
			for(int i=0;i<n;i++)
				a[i] = nextInt();
			return a;
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public char nextChar() {
			return next().toCharArray()[0];
		}
	}

}


// practice with kaiboy
import java.io.*;
import java.util.*;

public class CF1194D extends PrintWriter {
	CF1194D() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1194D o = new CF1194D(); o.main(); o.flush();
	}

	void main() {
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			if (k % 3 != 0)
				println(n % 3 != 0 ? "Alice" : "Bob");
			else {
				n %= k + 1;
				println(n == k || n % 3 != 0 ? "Alice" : "Bob");
			}
		}
	}
}


import java.io.*;
import java.util.*;

public class D {
    static int[] Grundy;
    static int GrundyNumbers(int n,int k){
        // this method was used to find the pattern
        if(n==0)return Grundy[n] = 0;
        if(Grundy[n]!=-1)return Grundy[n];
        TreeSet<Integer>tr = new TreeSet<>();
        for(int i=0;i<=5;i++){
            tr.add(i);
        }
        try {
            if(n-1>=0)
            tr.remove(GrundyNumbers(n - 1, k));
        }catch (Exception ex){}
        try{
            if(n-2>=0)
        tr.remove(GrundyNumbers(n-2,k));
        }catch (Exception ex){}
        try{
            if(n-k>=0)
        tr.remove(GrundyNumbers(n-k,k));
        }catch (Exception ex){}
        return Grundy[n] = tr.pollFirst();
    }
     public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
//        Grundy = new int[101];
//        Arrays.fill(Grundy,-1);
//        GrundyNumbers(100,4);
//         System.out.println(Arrays.toString(Grundy));
         int q = sc.nextInt();
         while (q-->0) {
             int n = sc.nextInt();
             int k = sc.nextInt();
             if (k % 3 == 0) {
                 n = n % (k + 1);
                 pw.println((n % 3 == 0 && n < k) ? "Bob" : "Alice");
             } else {
                 pw.println(n % 3 == 0 ? "Bob" : "Alice");
             }
         }
        pw.flush();
        pw.close();
    }
    static class FenwickTree { // one-based DS

        int n;
        int[] ft;

        FenwickTree(int size) { n = size; ft = new int[n+1]; }

        int rsq(int b) //O(log n)
        {
            int sum = 0;
            while(b > 0) { sum += ft[b]; b -= b & -b;}		//min?
            return sum;
        }

        int rsq(int a, int b) { return rsq(b) - rsq(a-1); }

        void point_update(int k, int val)	//O(log n), update = increment
        {
            while(k <= n) { ft[k] += val; k += k & -k; }		//min?
        }
        int get(int v){
            int sum =0;
            int id=0;
            for (int i =22;i>=0;i--){
                if (id+(1<<i)>n)
                    continue;
                if (sum+ft[id+(1<<i)]<v){
                    id+=(1<<i);
                    sum+=ft[id];
                }
            }
            return id+1;
        }
        public int findKthmin(int k){
            int a = 1;
            int b = n;
            int mid = 0;
            int res= 1;
            while (a<=b){
                mid = (a+b)/2;
                if(this.rsq(mid)>=k){
                    res =mid;
                    b = mid-1;
                }else{
                    a = mid+1;
                }
            }
            return res;
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x,int y){
            this.x= x;
            this.y = y;
        }
        public int compareTo(Pair p){
            if(this.x==p.x)
                return Long.compare(this.y,p.y);
            return -Long.compare(this.x,p.x);
        }
        public String toString(){
            return x+ " " + y;
        }
    }
    static class Pair2 implements Comparable<Pair2>{
        int x;
        int y;
        int index;
        public Pair2(int x,int y){
            this.x= x;
            this.y = y;
            this.index = index;
        }
        public int compareTo(Pair2 p){
            if(this.y==p.y)
                return Long.compare(p.x,this.x);
            return Long.compare(this.y,p.y);
        }

    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();

        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class OneTwoK {
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("template.in"));
		int N = Integer.parseInt(br.readLine());
		BitSet strip;
		String[] temp;
		int len, K;
		for (int i = 0; i < N; i++)
		{
			temp = br.readLine().split(" ");
			len = Integer.parseInt(temp[0]) + 1; // n+1 squares
			K = Integer.parseInt(temp[1]);
			strip = new BitSet(len);
			for (int j = 0; j < len; j++)
			{
				if (strip.get(j))
					continue;
				if (j+1 < len)
					strip.set(j+1);;
				if (j+2 < len)
					strip.set(j+2);
				if (j+K < len)
					strip.set(j+K);
			}
			if (strip.get(len-1))
				System.out.println("Alice");
			else
				System.out.println("Bob");
		}
		//PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("template.out")));
		//pw.println();
		//pw.close();
		br.close();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class OneTwoK {
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("template.in"));
		int N = Integer.parseInt(br.readLine());
		BitSet strip;
		String[] temp;
		int len, K, lastSquare;
		for (int i = 0; i < N; i++)
		{
			temp = br.readLine().split(" ");
			len = Integer.parseInt(temp[0]) + 1; // n+1 squares
			K = Integer.parseInt(temp[1]);
			/*strip = new BitSet(len);
			for (int j = 0; j < len; j++)
			{
				if (strip.get(j))
					continue;
				if (j+1 < len)
					strip.set(j+1);;
				if (j+2 < len)
					strip.set(j+2);
				if (j+K < len)
					strip.set(j+K);
			}
			for (int j = 0; j < len; j++)
				System.out.print(strip.get(j));
			System.out.println();
			if (strip.get(len-1))
				System.out.println("Alice");
			else
				System.out.println("Bob");*/
			if (K % 3 != 0)
			{
				if ((len-1)%3 == 0)
					System.out.println("Bob");
				else
					System.out.println("Alice");
			}
			else
			{
				if ((len - 1) % (K + 1) == 0)
					System.out.println("Bob");
				else if (((len-1)%(K+1)) % 3 == 0 && ((len-1)%(K+1)) != K)
					System.out.println("Bob");
				else
					System.out.println("Alice");
			}
		}
		//PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("template.out")));
		//pw.println();
		//pw.close();
		br.close();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class OneTwoK {
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("template.in"));
		int N = Integer.parseInt(br.readLine());
		byte[] strip;
		String[] temp;
		int len, K;
		for (int i = 0; i < N; i++)
		{
			temp = br.readLine().split(" ");
			len = Integer.parseInt(temp[0]) + 1; // n+1 squares
			K = Integer.parseInt(temp[1]);
			strip = new byte[len];
			for (int j = 0; j < strip.length; j++)
			{
				if (strip[j] == 1)
					continue;
				if (j+1 < len)
					strip[j+1] = 1;
				if (j+2 < len)
					strip[j+2] = 1;
				if (j+K < len)
					strip[j+K] = 1;
			}
			if (strip[len - 1] == 1)
				System.out.println("Alice");
			else
				System.out.println("Bob");
		}
		//PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("template.out")));
		//pw.println();
		//pw.close();
		br.close();
	}
}


	import java.io.*;
	import java.util.*;
	import java.math.*;

	 public class Main	{
	   static class Pair implements Comparable<Pair>{
//	   int a;
//	   int b;
//	   public Pair(){}
//	   public Pair(int x,int y){a=x;b=y;}
	   public int compareTo(Pair p){
		 return Double.compare(a, p.a);
	   }
//		   long a,b;
//		   public Pair(long x,long y){a=x;b=y;}
//		   public int compareTo(Pair p){
//				 return Long.compare(a, p.a);
//		   }
//
	   double a, b;
	   public Pair(double x, double y) {a=x;b=y;}
//		@Override
//		public int hashCode() {
//			final int prime = 31;
//			int result = 1;
//			result = prime * result + a;
//			result = prime * result + b;
//
//			return result;
//		}
		@Override
		public boolean equals(Object obj) {
			Pair cur = (Pair)obj;
			if((a==cur.a && b==cur.b))return true;
			return false;
		}
	 }
	static class TrieNode{
		int cnt;
		TrieNode[]child;
		public TrieNode() {
			cnt = 0;
			child = new TrieNode[10];
		}
	}
	  public static long gcd(long a,long b)
	  {
	    if(a<b)
	      return gcd(b,a);
	    if(b==0)
	      return a;
	    return gcd(b,a%b);

	  }
	  static int lcm(int a,int b) {
		  return  a*b / (int)gcd(a,b);
	  }

	  static long mod = 998244353;//(long)(1e9+7); //

	    public static void main(String[] args) throws Exception {
	       new Thread(null, null, "Anshum Gupta", 99999999) {
	            public void run() {
	                try {
	                    solve();
	                } catch(Exception e) {
	                    e.printStackTrace();
	                    System.exit(1);
	                }
	            }
	        }.start();
	    }

	static long pow(long x,long y){
	    if(y == 0)return 1;
	    if(y==1)return x;
	    long a = pow(x,y/2);
	    a = (a*a)%mod;
	    if(y%2==0){
	        return a;
	    }
	    return (a*x)%mod;
	}

	static long mxx;
	static int mxN = (int)(2e6+5);
	static int mxV = (int)(2e5);
	static long[]fact,inv_fact;
	static long my_inv(long a) {
		return pow(a,mod-2);
	}
	static long bin(int a,int b) {
		if(a < b || a<0 || b<0)return 0;
	    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
	}
		static ArrayList<ArrayList<Integer>>adj;
		static boolean[]vis;
	static void make_facts() {
	  fact=new long[mxN];
	  inv_fact = new long[mxN];
	  fact[0]=inv_fact[0]=1L;
	  for(int i=1;i<mxN;i++) {
		   fact[i] = (i*fact[i-1])%mod;
		   inv_fact[i] = my_inv(fact[i]);
	  }
	}

	 public static void solve() throws Exception {
	   // solve the problem here
	   MyScanner s = new MyScanner();
	        out = new PrintWriter(new BufferedOutputStream(System.out), true);
	        int tc = s.nextInt();
	        mxx = (long)(1e18+5);
	//	        make_facts();
	//	        int mod = (int)1e9+7;

	        while(tc-->0){
	        	long n = s.nextLong();
	        	long k = s.nextLong();
	        	boolean ok = true;
	        	if(k % 3 == 0) {
	        		long np = n % (k+1);
	        		if(np % 3 == 0 && np != k) {
	        			ok = false;
	        		}
	        	}
	        	else {
	        		long np = n % 3;
	        		if(np == 0)
	        			ok = false;
	        	}
	        	out.println(ok ? "Alice" : "Bob");
	        }

	        out.flush();
	}

	    //-----------PrintWriter for faster output---------------------------------
	    public static PrintWriter out;

	    //-----------MyScanner class for faster input----------
	    public static class MyScanner {
	        BufferedReader br;
	        StringTokenizer st;

	        public MyScanner() {
	            br = new BufferedReader(new InputStreamReader(System.in));
	        }

	        String next() {
	            while (st == null || !st.hasMoreElements()) {
	                try {
	                    st = new StringTokenizer(br.readLine());
	                } catch (IOException e) {
	                    e.printStackTrace();
	                }
	            }
	            return st.nextToken();
	        }

	        int nextInt() { return Integer.parseInt(next()); }
	        long nextLong() { return Long.parseLong(next()); }
	        double nextDouble() { return Double.parseDouble(next()); }

	        String nextLine(){
	            String str = "";
	            try {
	                str = br.readLine();
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            return str;
	        }
	    }
	    //--------------------------------------------------------
	}


#include <bits/stdc++.h>
// #define int long long
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ti tuple<int, int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) (((a)+(b)-1)/(b))
#define all(x) x.begin(), x.end()
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define dbg(msg, var) cerr << msg << " " << var << endl;

using namespace std;

const int MAX = 1e5+100;
const ll MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;
const ld PI = acos(-1);

// End Template //

int32_t main()
{sws;

    int t, n, k;
    cin >> t;
    while(t--){
        cin >> n >> k;
        if(k%3==0){
            n%=k+1;
            if(n==k)
                cout << "Alice\n";
            else if(n%3==0)
                cout << "Bob\n";
            else
                cout << "Alice\n";
        }else{
            if(n%3==0)
                cout << "Bob\n";
            else
                cout << "Alice\n";
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define Pi 3.14159265358979311599796346854
#define Eul 2.71828182845904509079559829842
#define mod 998244353
#define INF 999999999
#define MAX 100000010
#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vii vector< pair<int,int> >
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define endl '\n'

using namespace std;

int main()
{
	sws;

	int T, n, k;

	cin >> T;

	while(T--)
	{
		cin >> n >> k;
		if(n==k)
			cout << "Alice\n";
		else if(n<k and (n==0 or n+1==k))
			cout << "Bob\n";
		else if(n<k)
			cout << "Alice\n";
		else if(n>k)
		{
			if((n-1)%(k+1)==0)
				cout << "Bob\n";
			else
				cout << "Alice\n";
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define Pi 3.14159265358979311599796346854
#define Eul 2.71828182845904509079559829842
#define mod 998244353
#define INF 999999999
#define MAX 100000010
#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vii vector< pair<int,int> >
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define endl '\n'

using namespace std;

int main()
{
	sws;

	int T, n, k;

	cin >> T;

	while(T--)
	{
		cin >> n >> k;
		if(n==k)
			cout << "Alice\n";
		else if(n<k and (n==0 or k==n+1))
			cout << "Bob\n";
		else if(n<k and n!=0)
			cout << "Alice\n";
		else if(n>k)
		{
			if(n%(k+1)==0)
				cout << "Bob\n";
			else
				cout << "Alice\n";
		}
	}

	return 0;
}


#include <bits/stdc++.h>
// #define int long long
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ti tuple<int, int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) (((a)+(b)-1)/(b))
#define all(x) x.begin(), x.end()
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define dbg(msg, var) cerr << msg << " " << var << endl;

using namespace std;

const int MAX = 1e5+100;
const ll MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;
const ld PI = acos(-1);

// End Template //

int32_t main()
{sws;

    int t, n, k;
    cin >> t;
    while(t--){
        cin >> n >> k;
        if(k%3==0){
            if(n==k)
                cout << "Alice\n";
            else if(n%3==0)
                cout << "Bob\n";
            else
                cout << "Alice\n";
        }else{
            if(n%3==0)
                cout << "Bob\n";
            else
                cout << "Alice\n";
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define Pi 3.14159265358979311599796346854
#define Eul 2.71828182845904509079559829842
#define mod 998244353
#define INF 999999999
#define MAX 100000010
#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vii vector< pair<int,int> >
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define endl '\n'

using namespace std;

int main()
{
	sws;

	int T, n, k;

	cin >> T;

	while(T--)
	{
		cin >> n >> k;
		if(n==k)
			cout << "Alice\n";
		else if(n<k)
		{
			if(n==0)
				cout << "Bob\n";
			else if(n+1==k)
			{
				if(n%2==0)
					cout << "Alice\n";
				else
					cout << "Bob\n";
			}else
				cout << "Alice\n";
		}
		else if(n<k)
			cout << "Alice\n";
		else if(n>k)
		{
			if(n%(k+1)==0)
				cout << "Bob\n";
			else
				cout << "Alice\n";
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define Pi 3.14159265358979311599796346854
#define Eul 2.71828182845904509079559829842
#define mod 998244353
#define INF 999999999
#define MAX 100000010
#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vii vector< pair<int,int> >
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define endl '\n'

using namespace std;

int main()
{
	sws;

	int T, n, k;

	cin >> T;

	while(T--)
	{
		cin >> n >> k;
		if(n==k)
			cout << "Alice\n";
		else if(n<k)
		{
			if(n==0)
				cout << "Bob\n";
			else if(n+1==k)
			{
				if(n%2==0)
					cout << "Alice\n";
				else
					cout << "Bob\n";
			}
		}
		else if(n<k)
			cout << "Alice\n";
		else if(n>k)
		{
			if(n%(k+1)==0)
				cout << "Bob\n";
			else
				cout << "Alice\n";
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define Pi 3.14159265358979311599796346854
#define Eul 2.71828182845904509079559829842
#define mod 998244353
#define INF 999999999
#define MAX 100000010
#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vii vector< pair<int,int> >
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define endl '\n'

using namespace std;

int main()
{
	sws;

	int T, n, k;

	cin >> T;

	while(T--)
	{
		cin >> n >> k;
		if(n==k)
			cout << "Alice\n";
		else if(n<k and (n==0 or n+1==k))
			cout << "Bob\n";
		else if(n<k and n!=0)
			cout << "Alice\n";
		else if(n>k)
		{
			if(n%(k+1)==0)
				cout << "Bob\n";
			else
				cout << "Alice\n";
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define Pi 3.14159265358979311599796346854
#define Eul 2.71828182845904509079559829842
#define mod 998244353
#define INF 999999999
#define MAX 100000010
#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vii vector< pair<int,int> >
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define endl '\n'

using namespace std;

int main()
{
	sws;

	int T, n, k;

	cin >> T;

	while(T--)
	{
		cin >> n >> k;
		if(n==k)
			cout << "Alice\n";
		else if(n<k and (n==0 or k==n+1))
			cout << "Bob\n";
		else if(n<k and n!=0)
			cout << "Alice\n";
		else if(n>k)
		{
			if((n+1)%(k+1)==0)
				cout << "Bob\n";
			else
				cout << "Alice\n";
		}
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

string a = "Alice\n";
string b = "Bob\n";

void solve() {
	int n, k;
	cin >> n >> k; n++;
	if(n == k || n <= 2) {
		cout << b;
		return;
	}
	if(n % 2 != k % 2) {
		cout << a;
	} else {
		cout << b;
	}
}

// #define lolipop

signed main() {
#ifdef lolipop
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio();
	int t; cin >> t;
	while(t--) solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

string a = "Alice\n";
string b = "Bob\n";

void solve() {
	int n, k;
	cin >> n >> k; n;
	if(n == k || n <= 2) {
		cout << b;
		return;
	}
	// go to -3...
	if((n % k) % 3 == 0) {
		cout << b;
	} else {
		cout << a;
	}
}

// #define lolipop

signed main() {
#ifdef lolipop
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio();
	int t; cin >> t;
	while(t--) solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

string a = "Alice\n";
string b = "Bob\n";

void solve() {
	int n, k;
	cin >> n >> k;
	if(k % 3 != 0) {
		if(n % 3 == 0) {
			cout << b;
		} else {
			cout << a;
		}
	} else {
		n %= (k + 1);
		if(n == k) {
			cout << a;
			return;
		}
		if(n % 3 == 0) {
			cout << b;
		} else {
			cout << a;
		}
	}
}

// #define lolipop

signed main() {
#ifdef lolipop
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio();
	int t; cin >> t;
	while(t--) solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

string a = "Alice\n";
string b = "Bob\n";

void solve() {
	int n, k;
	cin >> n >> k;
	if(n == 0) {
		cout << b;
		return;
	}
	if(n == k || n <= 2) {
		cout << a;
		return;
	}
	if(k % 3 != 0) {
		if(n % 3 == 0) {
			cout << b;
		} else {
			cout << a;
		}
	} else {
		n %= k + 1;
		if(n == k) {
			cout << b;
			return;
		}
		if(n % 3 == 0) {
			cout << b;
		} else {
			cout << a;
		}
	}
}

// #define lolipop

signed main() {
#ifdef lolipop
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio();
	int t; cin >> t;
	while(t--) solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

string a = "Alice\n";
string b = "Bob\n";

void solve() {
	int n, k;
	cin >> n >> k;
	if(n == k || n <= 2) {
		cout << b;
		return;
	}
	if(n % 2 == k % 2) {
		cout << a;
	} else {
		cout << b;
	}
}

// #define lolipop

signed main() {
#ifdef lolipop
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio();
	int t; cin >> t;
	while(t--) solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

string a = "Alice\n";
string b = "Bob\n";

void solve() {
	int n, k;
	cin >> n >> k; n++;
	if(n == k || n <= 2) {
		cout << b;
		return;
	}
	// go to -3...
	if((n % k) % 3 == 0) {
		cout << b;
	} else {
		cout << a;
	}
}

// #define lolipop

signed main() {
#ifdef lolipop
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio();
	int t; cin >> t;
	while(t--) solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

string a = "Alice\n";
string b = "Bob\n";

void solve() {
	int n, k;
	cin >> n >> k;
	if(n == 0) {
		cout << b;
		return;
	}
	if(n == k || n <= 2) {
		cout << a;
		return;
	}
	if(k % 3 != 0) {
		if(n % 3 == 0) {
			cout << b;
		} else {
			cout << a;
		}
	} else {
		n = (n+1)%k;
		if(n == k) {
			cout << b;
			return;
		}
		if(n % 3 == 0) {
			cout << b;
		} else {
			cout << a;
		}
	}
}

// #define lolipop

signed main() {
#ifdef lolipop
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio();
	int t; cin >> t;
	while(t--) solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

string a = "Alice\n";
string b = "Bob\n";

void solve() {
	int n, k;
	cin >> n >> k; n;
	if(n == 0) {
		cout << b;
		return;
	}
	if(n == k || n <= 2) {
		cout << a;
		return;
	}
	// go to -3...
	if((n % k) % 3 == 0) {
		cout << b;
	} else {
		cout << a;
	}
}

// #define lolipop

signed main() {
#ifdef lolipop
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio();
	int t; cin >> t;
	while(t--) solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

string a = "Alice\n";
string b = "Bob\n";

void solve() {
	int n, k;
	cin >> n >> k;
	if(n % 2 == k % 2) {
		cout << a;
	} else {
		cout << b;
	}
}

// #define lolipop

signed main() {
#ifdef lolipop
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio();
	int t; cin >> t;
	while(t--) solve();
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
map<ll,ll>sg;
ll k,n;
map<ll,ll>vis;
int choice[3];
void get_sg()
{
	sg[0]=0;
	for(int i=1;i<=n;i++)
	{
		vis.clear();
		for(int j=0;j<3;j++)
		{
			if(i<choice[j])continue;
			vis[sg[i-choice[j]]]++;
		}
		for(int j=0;j<=n;j++)
		{
			if(!vis[j])
			{
				sg[i]=j;
				break;
			}
		}
	}
}
int main(int argc, char const *argv[])
{
	io();
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n>>k;
		n=n%(k+1);
		choice[0]=1;
		choice[1]=2;
		choice[2]=k;
		sg.clear();
		get_sg();
		if(sg[n]<=0)cout<<"Bob"<<endl;
		else cout<<"Alice"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
map<ll,ll>sg;
ll k,n;
map<ll,ll>vis;
int choice[3];
void get_sg()
{
	sg[0]=0;
	for(int i=1;i<=n;i++)
	{
		vis.clear();
		for(int j=0;j<3;j++)
		{
			if(i<choice[j])continue;
			vis[sg[i-choice[j]]]++;
		}
		for(int j=0;j<=n;j++)
		{
			if(!vis[j])
			{
				sg[i]=j;
				break;
			}
		}
	}
	// for(int i=0;i<=n;i++)
	// 	cout<<sg[i]<<" ";
	// cout<<endl;
}
int main(int argc, char const *argv[])
{
	io();
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n>>k;
		choice[0]=1;
		choice[1]=2;
		choice[2]=k;
		sg.clear();
		get_sg();
		ll res=0;
		for(int i=0;i<3;i++)
		{
			if(n>=choice[i])res^=sg[n-choice[i]];
		}
		// cout<<res<<endl;
		if(sg[n]<=0)cout<<"Bob"<<endl;
		else cout<<"Alice"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int main(int argc, char const *argv[])
{
	io();
	int t;
	cin>>t;
	ll n,k;
	while(t--)
	{
		cin>>n>>k;
		int win=0;
		// if(k%3==0)n%=(k+1);
		if((n+1)%3==1&&n!=k)cout<<"Bob"<<endl;
		else cout<<"Alice"<<endl;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int inn=0x80808080;
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        int n,k;
        cin>>n>>k;
        if(k%3==0){//这时候和没有k的情况一样
            if(n%3!=0){//处于必胜点
                cout<<"Alice"<<endl;
            }else{
                cout<<"Bob"<<endl;
            }
        }else{
            int t=n%(k+1);
            if(t%3!=0||t==k){//必胜点
                cout<<"Alice"<<endl;
            }else{//必败点
                cout<<"Bob"<<endl;
            }
        }
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int inn=0x80808080;
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        int n,k;
        cin>>n>>k;
        if(k%3!=0){//这时候和没有k的情况一样
            if(n%3!=0){//处于必胜点
                cout<<"Alice"<<endl;
            }else{
                cout<<"Bob"<<endl;
            }
        }else{
            int t=n%(k+1);
            if(t%3!=0||t==k){//必胜点
                cout<<"Alice"<<endl;
            }else{//必败点
                cout<<"Bob"<<endl;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
map<ll,ll>sg;
ll k,n;
map<ll,ll>vis;
int choice[3];
void get_sg()
{
	sg[0]=0;
	for(int i=1;i<=n;i++)
	{
		vis.clear();
		for(int j=0;j<3;j++)
		{
			if(i<choice[j])continue;
			vis[sg[i-choice[j]]]++;
		}
		for(int j=0;j<=n;j++)
		{
			if(!vis[j])
			{
				sg[i]=j;
				break;
			}
		}
	}
	// for(int i=0;i<=n;i++)
	// 	cout<<sg[i]<<" ";
	// cout<<endl;
}
int main(int argc, char const *argv[])
{
	io();
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n>>k;
		choice[0]=1;
		choice[1]=2;
		choice[2]=k;
		sg.clear();
		get_sg();
		ll res=0;
		for(int i=0;i<3;i++)
		{
			if(n>=choice[i])res^=sg[n-choice[i]];
		}
		// cout<<res<<endl;
		if(sg[n])cout<<"Bob"<<endl;
		else cout<<"Alice"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int main(int argc, char const *argv[])
{
	io();
	int t;
	cin>>t;
	ll n,k;
	while(t--)
	{
		cin>>n>>k;
		int win=0;
		if(k%3==0)n%=(k+1);
		if((n+1)%3==1&&n!=k)cout<<"Bob"<<endl;
		else cout<<"Alice"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int main(int argc, char const *argv[])
{
	io();
	int t;
	cin>>t;
	ll n,k;
	while(t--)
	{
		cin>>n>>k;
		int win=0;
		n%=(k+1);
		if((n+1)%3!=1&&n!=k)cout<<"Bob"<<endl;
		else cout<<"Alice"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
#define endll "\n"
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		int n, k, tar;
		cin>>n>>k;
		int moves = n/k;
		n-=k*moves;
		//cout<<n<<" "<<moves<<endl;
		moves += n/2;
		n-=2*moves;
		moves+=n;
		if(moves%2)cout<<"Alice\n";
		else cout<<"Bob\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		int n, k, tar;
		cin>>n>>k;
		bool can;
		if(n==0)can=false;
		else if(n==k)can=true;
		else if(n>k)can=(n-k)%2;
		else can=(n-3)%2;

		if(can)cout<<"Alice\n";
		else cout<<"Bob\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		int n, k, tar;
		cin>>n>>k;
		bool can;
		if(n==0)can=false;
		else if(n==k)can=true;
		else if(n>k)can=(n-k)%2==0;
		else can=(n-2)%2==0;

		if(can)cout<<"Alice\n";
		else cout<<"Bob\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		int n, k, tar;
		cin>>n>>k;
		n%=k+1;
		bool can = n%3 || n==k;

		if(can)cout<<"Alice\n";
		else cout<<"Bob\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
#define endll "\n"
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		int n, k, tar;
		cin>>n>>k;
		int moves = n/k;
		n-=k*moves;
		//cout<<n<<" "<<moves<<endl;
		moves+=max(0,n-3);
		if(moves%2)cout<<"Alice\n";
		else cout<<"Bob\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		int n, k, tar;
		cin>>n>>k;
		bool can;
		if(n==0)can=false;
		else if(n==k)can=true;
		else if(k-n>2)can=n%2==0;
		else if(n>k)can=n%k==0;
		else if(n==k-1)can=false;

		else can=true;

		if(can)cout<<"Alice\n";
		else cout<<"Bob\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		int n, k, tar;
		cin>>n>>k;
		bool can;
		if(n==0)can=false;
		else if(n==k)can=true;
		else if(n>k)can=n%(k)==0;
		else can=n%(k-1);

		if(can)cout<<"Alice\n";
		else cout<<"Bob\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		int n, k, tar;
		cin>>n>>k;
		bool can;
		if(n==0)can=false;
		else if(n==k)can=true;
		else if(n>k)can=n%k==0;
		else can=(n-3)%2;

		if(can)cout<<"Alice\n";
		else cout<<"Bob\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		int n, k, tar;
		cin>>n>>k;
		bool can;
		if(n==0)can=false;
		else if(n==k)can=true;
		else if(n>k)can=n%(k+1)==0;
		else can=n%(k-1);

		if(can)cout<<"Alice\n";
		else cout<<"Bob\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		int n, k, tar;
		cin>>n>>k;
		bool can;
		if(n==0)can=false;
		else if(n==k)can=true;
		else if(n>k)can=n%k==0;
		else can=(n-3)%2==0;

		if(can)cout<<"Alice\n";
		else cout<<"Bob\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		int n, k, tar;
		cin>>n>>k;
		bool can;
		if(n==0)can=false;
		else if(n==k)can=true;
		else if(n>k)can=n%k==0;
		else can=n%2==0;

		if(can)cout<<"Alice\n";
		else cout<<"Bob\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		int n, k, tar;
		cin>>n>>k;
		if(k%3==0)n%=k+1;
		bool can = n%3 || n==k;

		if(can)cout<<"Alice\n";
		else cout<<"Bob\n";
	}
	return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<map>

using namespace std;

int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");

    long long q;
    cin >> q;
    for(int q1 = 0; q1 < q; q1++)
    {
        long long n, k;
        cin >> n >> k;
        if(n < k)
        {
            if(n % 3 == 0) cout << "Bob" << "\n";
            else cout << "Alice" << "\n";
        }
        else if(k == 3)
        {
            if(n % 4 == 0) cout << "Bob" << "\n";
            else cout << "Alice" << "\n";
        }
        else
        {
            k--;
            if(k % 3 == 0 || k % 3 == 1)
            {
                if(n % 3 == 0) cout << "Bob" << "\n";
                else cout << "Alice" << "\n";
            }
            else
            {
                if((n - k + 1) % 10 < 3 || (n - k + 1) % 10 == 4 || (n - k + 1) % 10 == 5 || (n - k + 1) % 10 == 7 || (n - k + 1) % 10 == 8) cout << "Alice" << "\n";
                else cout << "Bob" << "\n";
            }

        }
    }
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<map>

using namespace std;

int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");

    long long q;
    cin >> q;
    for(int q1 = 0; q1 < q; q1++)
    {
        long long n, k;
        cin >> n >> k;
        if(n < k)
        {
            if(n % 3 == 0) cout << "Bob" << "\n";
            else cout << "Alice" << "\n";
        }
        else if(k == 3)
        {
            if(n % 4 == 0) cout << "Bob" << "\n";
            else cout << "Alice" << "\n";
        }
        else
        {
            k--;
            if(k % 3 == 0 || k % 3 == 1)
            {
                if(n % 3 == 0) cout << "Bob" << "\n";
                else cout << "Alice" << "\n";
            }
            else
            {
                int i = 0;
                int a[100] = {};
                a[0] = 0;
                bool c = false;
                while(a[i] != 0 || a[i + 3] != 1 || c == false)
                {
                    if(a[i] == 0 && a[i + 3] == 1) c = true;
                    if(a[i] == 0) a[i + 1] = a[i + 2] = 1;
                    if(a[i] == 0) a[i + k + 1] = 1;
                    if(a[i] == 0) i += 2;
                    else i++;
                }
                //for(int i = 0; i < 39; i++) cout << a[i] << " ";
                //cout << endl;
                if(a[(n - k + 1) % (i - k + 2) + k - 1]) cout << "Alice" << "\n";
                else cout << "Bob" << "\n";
            }

        }
    }
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<map>

using namespace std;

int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");

    long long q;
    cin >> q;
    for(int q1 = 0; q1 < q; q1++)
    {
        long long n, k;
        cin >> n >> k;
        if(n < k)
        {
            if(n % 3 == 0) cout << "Bob" << "\n";
            else cout << "Alice" << "\n";
        }
        else if(k == 3)
        {
            if(n % 4 == 0) cout << "Bob" << "\n";
            else cout << "Alice" << "\n";
        }
        else
        {
            if(k % 3 == 0 || k % 3 == 1)
            {
                if(n % 3 == 0) cout << "Bob" << "\n";
                else cout << "Alice" << "\n";
            }
            else
            {
                if((n - k + 1) % 10 < 3 || (n - k + 1) % 10 == 4 || (n - k + 1) % 10 == 5 || (n - k + 1) % 10 == 7 || (n - k + 1) % 10 == 8) cout << "Alice" << "\n";
                else cout << "Bob" << "\n";
            }

        }
    }
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<map>

using namespace std;

int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");

    long long q;
    cin >> q;
    for(int q1 = 0; q1 < q; q1++)
    {
        long long n, k;
        cin >> n >> k;
        if(n < k)
        {
            if(n % 3 == 0) cout << "Bob" << "\n";
            else cout << "Alice" << "\n";
        }
        else if(k == 3)
        {
            if(n % 4 == 0) cout << "Bob" << "\n";
            else cout << "Alice" << "\n";
        }
        else
        {
            k--;
            if(k % 3 == 0 || k % 3 == 1)
            {
                if(n % 3 == 0) cout << "Bob" << "\n";
                else cout << "Alice" << "\n";
            }
            else
            {
                int i = 0;
                int a[100] = {};
                a[0] = 0;
                bool c = false;
                while(a[i] != 0 || a[i + 3] != 1 || c == false)
                {
                    if(a[i] == 0 && a[i + 3] == 1) c = true;
                    if(a[i] == 0) a[i + 1] = a[i + 2] = 1;
                    if(i + k + 1 < 100 && a[i] == 0) a[i + k + 1] = 1;
                    if(a[i] == 0) i += 2;
                    else i++;
                }
                //for(int i = 0; i < 39; i++) cout << a[i] << " ";
                //cout << endl;
                if(a[(n - k + 1) % (i - k + 2) + k - 1]) cout << "Alice" << "\n";
                else cout << "Bob" << "\n";
            }

        }
    }
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<map>

using namespace std;

int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");

    long long q;
    cin >> q;
    for(int q1 = 0; q1 < q; q1++)
    {
        long long n, k;
        cin >> n >> k;
        if(n < k)
        {
            if(n % 3 == 0) cout << "Bob" << "\n";
            else cout << "Alice" << "\n";
        }
        else if(k == 3)
        {
            if(n % 4 == 0) cout << "Bob" << "\n";
            else cout << "Alice" << "\n";
        }
        else
        {
            k--;
            if(k % 3 == 0 || k % 3 == 1)
            {
                if(n % 3 == 0) cout << "Bob" << "\n";
                else cout << "Alice" << "\n";
            }
            else
            {
                int i = 0;
                map<int, int> a;
                a[0] = 0;
                bool c = false;
                while(i < n && a[i] != 0 || a[i + 3] != 1 || c == false)
                {
                    if(a[i] == 0 && a[i + 3] == 1) c = true;
                    if(a[i] == 0) a[i + 1] = a[i + 2] = 1;
                    if(i + k + 1 < 100 && a[i] == 0) a[i + k + 1] = 1;
                    if(a[i] == 0) i += 2;
                    else i++;
                }
                //for(int i = 0; i < 39; i++) cout << a[i] << " ";
                //cout << endl;
                if(a[(n - k + 1) % (i - k + 2) + k - 1]) cout << "Alice" << "\n";
                else cout << "Bob" << "\n";
            }

        }
    }
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<map>

using namespace std;

int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");

    long long q;
    cin >> q;
    for(int q1 = 0; q1 < q; q1++)
    {
        long long n, k;
        cin >> n >> k;
        if(n < k)
        {
            if(n % 3 == 0) cout << "Bob" << "\n";
            else cout << "Alice" << "\n";
        }
        else if(k == 3)
        {
            if(n % 4 == 0) cout << "Bob" << "\n";
            else cout << "Alice" << "\n";
        }
        else
        {
            k--;
            if(k % 3 == 0 || k % 3 == 1)
            {
                if(n % 3 == 0) cout << "Bob" << "\n";
                else cout << "Alice" << "\n";
            }
            else
            {
                int i = 0;
                map<int, int> a;
                a[0] = 0;
                bool c = false;
                while(a[i] != 0 || a[i + 3] != 1 || c == false)
                {
                    if(a[i] == 0 && a[i + 3] == 1) c = true;
                    if(a[i] == 0) a[i + 1] = a[i + 2] = 1;
                    if(i + k + 1 < 100 && a[i] == 0) a[i + k + 1] = 1;
                    if(a[i] == 0) i += 2;
                    else i++;
                }
                //for(int i = 0; i < 39; i++) cout << a[i] << " ";
                //cout << endl;
                if(a[(n - k + 1) % (i - k + 2) + k - 1]) cout << "Alice" << "\n";
                else cout << "Bob" << "\n";
            }

        }
    }
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
int ask(int l,int r,int aa,int bb,int k);
int ask1(int l,int r,int aa,int bb,int k);
void build(int l,int r,int k);
using namespace std;
typedef long long ll;
int tree[1000000];
int tree2[1000000];
int a[400005];
int main(void)
{
    int i,j,k,p,q;
    tree[0]=0;
    int nn,mm,kk;
    while(scanf("%d %d",&p,&q)!=EOF)
    {
        for(i=1; i<=p; i++)
        {
            scanf("%d",&a[i]);
        }
        build(1,p,0);
        while(q--)
        {
            scanf("%d %d %d",&nn,&mm,&kk);
            a[0]=0;
            int maxxid=ask(nn,mm,1,p,0);
            a[0]=1e8;
            int minnid=ask1(nn,mm,1,p,0);
            int maxx=a[maxxid];
            int minn=a[minnid];
            if(kk==maxx&&kk==minn)
            {
                printf("-1\n");
            }
            else
            {
                if(kk!=maxx)
                {
                    printf("%d\n",maxxid);
                }
                else printf("%d\n",minnid);
            }
        }
    }
    return 0;
}

void build(int l,int r,int k)
{
    if(l==r)
    {
        tree[k]=l;
        tree2[k]=l;
        return ;
    }
    else
    {
        build(l,(l+r)/2,2*k+1);
        build((l+r)/2+1,r,2*k+2);
        tree[k]=a[tree[2*k+1]]>a[tree[2*k+2]]?tree[2*k+1]:tree[2*k+2];
        tree2[k]=a[tree2[2*k+1]]<a[tree2[2*k+2]]?tree2[2*k+1]:tree2[2*k+2];
    }
}
int ask(int l,int r,int aa,int bb,int k)
{
    if(l>bb||r<aa)
    {
        return 0;
    }
    else if(l<=aa&&r>=bb)
    {
        return tree[k];
    }
    else
    {
        int ll=ask(l,r,aa,(aa+bb)/2,2*k+1);
        int uu=ask(l,r,(aa+bb)/2+1,bb,2*k+2);
        return a[ll]>a[uu]?ll:uu;
    }

}
int ask1(int l,int r,int aa,int bb,int k)
{
    if(l>bb||r<aa)
    {
        return 0;
    }
    else if(l<=aa&&r>=bb)
    {
        return tree2[k];
    }
    else
    {
        int ll=ask1(l,r,aa,(aa+bb)/2,2*k+1);
        int uu=ask1(l,r,(aa+bb)/2+1,bb,2*k+2);
        return a[ll]<a[uu]?ll:uu;
    }
}


// CodeForces_Round_7_C.cpp : 定义控制台应用程序的入口点。
//
#include <stdio.h>
#include <tchar.h>
#include <SDKDDKVer.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	int n,m;
	cin>>n>>m;
	int a[100000];
	int b[3];
	int cont = -1;
	for(int i = 1;i<=n;i++)
		cin>>a[i];
	for(int i = 1;i<=m;i++){
		cin>>b[0]>>b[1]>>b[2];
		for(int j = b[0];j<=b[1];j++){
			if(a[j]!= b[2]){
				cont = j;
				break;
			}
		}
		cout<<cont<<endl;
	}
	return 0;
}


// CodeForces_Round_7_C.cpp : 定义控制台应用程序的入口点。
//
#include <stdio.h>
#include <tchar.h>
#include <SDKDDKVer.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	int n,m;
	cin>>n>>m;
	int a[100000];
	int b[3];
	int cont;
	for(int i = 1;i<=n;i++)
		cin>>a[i];
	for(int i = 1;i<=m;i++){
		cin>>b[0]>>b[1]>>b[2];
		for(int j = b[0];j<=b[1];j++){
			if(a[j]!= b[2]){
				cont = j;
				break;
			}
			else{
				cont = -1;
			}
		}
		cout<<cont<<endl;
	}
	return 0;
}


// CodeForces_Round_7_C.cpp : 定义控制台应用程序的入口点。
//
#include <stdio.h>
#include <tchar.h>
#include <SDKDDKVer.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	int n,m;
	cin>>n>>m;
	int a[100000];
	int b[3];

	for(int i = 1;i<=n;i++)
		cin>>a[i];
	for(int i = 1;i<=m;i++){
		int cont = -1;
		cin>>b[0]>>b[1]>>b[2];
		for(int j = b[0];j<=b[1];j++){
			if(a[j]!= b[2]){
				cont = j;
				break;
			}
		}
		cout<<cont<<endl;
	}
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<string>
#include<cstring>
#include <iomanip>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#include<set>
#include<bitset>
#include<map>
#include<queue>
#include<math.h>
#include <time.h>
using namespace std;
//set<int>::iterator it;
#define mdlo 1000000007
#define maxERR 0.00000002
//#define minVal -10000000000000
#define maxBits 40
#define pi 3.1415926535897932384626433832795
#define INF 999999999999
#define lim 10000007
typedef long long ll;
long long mInv[41];
long long fact[41];
long long factInv[41];
map<long,long>mymap;
typedef pair<ll,ll>skill;
typedef pair<ll,ll>depth;
typedef vector<long>adj;
vector<long>primes;
set<long>candidates;

set<string>dictionary;
set<string>::iterator it;
pair<set<string>::iterator,bool> ret;
string ai,phn;
long len;
bool doesMatch(long pos){
	for(long i=0;i<len;i++){
		if(ai[pos+i]!=phn[i])
			return false;
	}
	return true;
}
long long getmoduloInv(long long n){
    if(n==1)
        return 1;
    if(mInv[n]>0)
        return mInv[n];
    long long m=(-1*mdlo)/n;
    m+=mdlo;
    m*=getmoduloInv(mdlo%n);
    mInv[n]=(m%mdlo);
    return mInv[n];
}
long num[200006],startTingPos[200005];
//ll times[1001006];

vector< long> get_primes(unsigned long max){

    char *sieve;
    sieve = new char[max/8+1];
    // Fill sieve with 1
    long m=(max/8)+1;
    for(long long i=0;i<m;i++)
        sieve[i]=255;
    for(unsigned long x = 2; x <= max; x++)
        if(sieve[x/8] & (0x01 << (x % 8))){
            primes.push_back(x);
            // Is prime. Mark multiplicates.
            for(unsigned long j = 2*x; j <= max; j += x)
                sieve[j/8] &= ~(0x01 << (j % 8));
        }
    delete[] sieve;
    return primes;
}

int main(void){
//  freopen ("E:/inputSmall.txt","r",stdin);
//  freopen ("E:/outputSmall2.txt","w",stdout);
    ll test_cases=1;//,C,D,A,L,R,rep,round=0,rem,num;
   //cin>>test_cases>>r>>v;
    cout << setprecision(15) << fixed;
//	get_primes(32000);
	long n,k,m,l,r,x;
    cin>>n>>m;
	num[0]=-1;
	for(long i=1;i<=n;i++){
		scanf("%ld",&num[i]);
		if(num[i]==num[i-1])
			startTingPos[i]=startTingPos[i-1];
		else
			startTingPos[i]=i;
	}
	for(long i=0;i<m;i++){
		scanf("%ld",&l);
		scanf("%ld",&r);
		scanf("%ld",&x);
		if(num[r]!=x)
			printf("%ld\n",r);
		else if(startTingPos[r]>l)
			printf("%ld\n",startTingPos[r]-1);
		else
			printf("-1\n");
	}

    return 0;
}
/*ll cumDist1[100005];
ll cumDist2[100005];
vector<ll>distFrom1;
vector<ll>distFrom2;
void initFact(){
    fact[0]=1;
    factInv[0]=1;
    for(ll i=1;i<0;i++){
        factInv[i]=(factInv[i-1]*getmoduloInv(i))%mdlo;
        fact[i]=(fact[i-1]*i)%mdlo;
    }
}
bool isLeapyear(long year){
    if(year%4==0&&(year%100!=0||year%400==0))
        return true;
    return false;
}
ll ds,ms,ys,de,me,ye,dc,mc,yc,day;
void next13th(){
    if(ds<13){
        ds=13;
        return;
    }
    ms++;
    ds=13;
    if(ms>12)
    {
        ms=1;
        ys++;
    }
}
    long months[]={31,28,31,30,31,30,31,31,30,31,30,31};
    long dayBeforeMonth[12];
bool validDate(){
    if(ys>ye)
        return false;
    if(ys<ye)
        return true;
    if(ms>me)
        return false;
    if(ms<me)
        return true;
    if(ds>de)
        return false;
    return true;
}
long getDay(long d,long m,long y){
    long day=((y-1900)*365+(y-1900)/4-(y-1900)/100+(y-1600)/400+dayBeforeMonth[m-1]+d+2)%7;
    if(y%4==0&&m<3){
        if(y%400==0||y%100!=0)
            day=(day+6)%7;
    }
    return day;
}
bool iscurDayFriday(){
    if(getDay(ds,ms,ys)==0)
        return true;
    return false;
}
void dijkstra(long startPoint){
    long m;
    if(startPoint==1)
        m=0;
    else
        m=1;
    distMatrix[m][startPoint]=0;
    priority_queue<edge, vector<edge>,greater <edge>>pq;
    pq.push(edge(0,startPoint));
    while(!pq.empty()){
        edge top=pq.top();
        pq.pop();
        ll d= top.first,u=top.second;
        if(distMatrix[m][u]==d){
            for(long i=0;i<graph[u].size();i++){
                ll v=graph[u][i].second;
                ll ec=graph[u][i].first;
                if(distMatrix[m][v]>distMatrix[m][u]+ec){
                    distMatrix[m][v]=distMatrix[m][u]+ec;
                    pq.push(edge(distMatrix[m][v],v));
                }
            }
        }
    }
}
ll vals[1];
ll dp[1];
ll totalSum[1];
long long mInv[1];
long long fact[1];
long long factInv[1];

//long long pow10[18];
long long getmoduloInv(long long n){
    if(n==1)
        return 1;
    if(mInv[n]>0)
        return mInv[n];
    long long m=(-1*mdlo)/n;
    m+=mdlo;
    m*=getmoduloInv(mdlo%n);
    mInv[n]=(m%mdlo);
    return mInv[n];
}
long long onNthbit(long pos,long val){
    return val|pwr2[pos];
}
bool isNthbitOn(long long pos,long long val){
    return (val&pwr2[pos])>0;
}

seg segTree[5];
long N;
void buildSumSegmentTree(long long b,long long e,long long node){
    if(b==e)
    {
         segTree[node].first=vals[b];
         return;
    }
    long long mid=(b+e)/2;
    buildSumSegmentTree(b,mid,node*2);
    buildSumSegmentTree(mid+1,e,1+(node*2));
    segTree[node].first=segTree[2*node].first+segTree[1+(node*2)].first;
}
long long getSum(long long qStart,long long qEnd,long long sStart,long long sEnd,long long node,prop p){

    long k=sEnd-sStart,n;
    for(long i=0;i<p.size();i++){
        segTree[node].second.push_back(p[i]);
        n=p[i];
        segTree[node].first+=(((n+k)*(n+k+1)*(2*n+2*k+1)-(n*(n-1)*(2*n-1)))/6+((n+k)*(n+k+1)-n*(n-1)))/2;
        }
    if(qEnd<sStart||qStart>sEnd)
    {
        return 0;
    }
    if(sStart>=qStart&&sEnd<=qEnd)
    {
         return segTree[node].first;
    }
    long long sMid=(sStart+sEnd)/2;
    prop l;
    for(long i=0;segTree[node].second.size();i++)
        l.push_back(segTree[node].second[i]+sMid+1-sStart);
    return getSum(qStart,qEnd,sStart,sMid,2*node,segTree[node].second)+getSum(qStart,qEnd,sMid+1,sEnd,1+(2*node),l);
}
long long update(ll node, long long sStart,ll sEnd,long upStart,long upEnd){
    if(upEnd<sStart||upStart>sEnd)
        return 0;
    long k=sEnd-sStart,n=sStart+1-upStart;
    if(upStart<=sStart&&upEnd>=sEnd){
        segTree[node].second.push_back(n);
        segTree[node].first+=(((n+k)*(n+k+1)*(2*n+2*k+1))/6);
        segTree[node].first-=(((n*(n-1)*(2*n-1)))/6);
        segTree[node].first+=(((n+k)*(n+k+1)-n*(n-1)))/2;
        return 0;
    }
    ll sMid=(sStart+sEnd)/2;
    update(node*2,sStart,sMid,upStart,upEnd);
    update(1+(node*2),sMid+1,sEnd,upStart,upEnd);
    segTree[node].first=segTree[2*node].first+segTree[1+(node*2)].first;

    for(long i=0;i<segTree[node].second.size();i++){
        n=segTree[node].second[i];
        segTree[node].first+=(((n+k)*(n+k+1)*(2*n+2*k+1)-(n*(n-1)*(2*n-1)))/6+((n+k)*(n+k+1)-n*(n-1)))/2;
    }
    return segTree[node].first;
}
void update(long x,long y){
    long len=y-x+1,add=0;
    for(long i=0;i<len;i++){
        add+=(i+1)*2;
        update(1,0,N-1,x+i,add+vals[x+i]);
    }
}
long getlen(long long num){
    long len=0;
    while(num>0){
        num/=10;
        len++;
    }
    return len;
}
encryptedLine lineConverter(string s){
    encryptedLine el;
    ll val=0,len=s.size();
    for(long i=0;i<len;i++){
        if(s[i]==' '){
            el.push_back(val);
            val=0;
        }
        else{
            val*=26;
            val+=(s[i]-'a');
        }
    }
    el.push_back(val);
    return el;
}
long getPalinDrome(long num){
    long a=num%10;
    long b=(num/10)%10;
    long c=(num/100)%10;
    return num*1000+a*100+b*10+c;
}

vector<unsigned long> get_primes(unsigned long max){
    vector<unsigned long> primes;
    char *sieve;
    sieve = new char[max/8+1];
    // Fill sieve with 1
    long m=(max/8)+1;
    for(long long i=0;i<m;i++)
        sieve[i]=255;
    for(unsigned long x = 2; x <= max; x++)
        if(sieve[x/8] & (0x01 << (x % 8))){
            primes.push_back(x);
            // Is prime. Mark multiplicates.
            for(unsigned long j = 2*x; j <= max; j += x)
                sieve[j/8] &= ~(0x01 << (j % 8));
        }
    delete[] sieve;
    return primes;
}string add(string a,string b){
    int l1=a.size();
    int l2=b.size();
    while(l1<l2){
        a="0"+a;
        l1++;
    }
    while(l2<l1){
        b="0"+b;
        l2++;
    }
    string s;
    int carry=0;
    for(long i=l2-1;i>-1;i--){
        int d=a[i]+b[i]+carry-2*'0';
        carry=d/10;
        a[i]='0'+(d%10);
    }
    if(carry)
        a="1"+a;
    return a;
}
long long mInv[1010];
long long fact[1000];
long long factInv[1000];
long long getmoduloInv(long long n){
    if(n==1)
        return 1;
    if(mInv[n]>0)
        return mInv[n];
    long long m=(-1*mdlo)/n;
    m+=mdlo;
    m*=getmoduloInv(mdlo%n);
    mInv[n]=(m%mdlo);
    return mInv[n];

}

long dp[200010];
vector<weightedPos>points;
vector<weightedPos>modifiedPositions;
vector<long long>weightPlusPos;
long long segTree[530010];
long N,X,W;
void buildSegTree(long node,long b,long e){
    if(b==e)
        segTree[node]=b;
    else{
        long mid=(b+e)/2;
        buildSegTree(node*2,b,mid);
        buildSegTree(1+node*2,mid+1,e);
        if(weightPlusPos[segTree[node*2]]<=weightPlusPos[segTree[1+node*2]])
            segTree[node]=segTree[node*2];
        else
            segTree[node]=segTree[1+node*2];
    }
}
long long getMin(long node,long segBeg,long segEnd,long qBeg,long qEnd){
    if(segEnd<qBeg||segBeg>qEnd)
        return N;
    if(segBeg>=qBeg&&segEnd<=qEnd)
        return segTree[node];
    long mid=(segBeg+segEnd)/2;
    long fh=getMin(node*2,segBeg,mid,qBeg,qEnd);
    long sh=getMin(1+node*2,mid+1,segEnd,qBeg,qEnd);
    if(weightPlusPos[sh]<weightPlusPos[fh])
        return sh;
    return fh;
}
long long getMinPos(long node,long segBeg,long segEnd,long qBeg,long qEnd){
    if(segEnd<qBeg||segBeg<qEnd)
        return 0;
    if(segBeg>=qBeg&&segEnd<=qEnd)
        return segTree[node];
    long mid=(segBeg+segEnd)/2;
    long fh=getMin(node*2,segBeg,mid,qBeg,qEnd);
    long sh=getMin(node*2,mid+1,segEnd,qBeg,qEnd);
    return min(fh,sh);
}
long getPos(long val){
    long low=0,high=modifiedPositions.size()-1;
    long mid=(low+high)/2;
    while(low<high){
        if(modifiedPositions[mid].first<val)
            low=mid+1;
        else
            high=mid-1;
        mid=(low+high)/2;
    }
    if(mid>0)
        mid--;
    while(mid<modifiedPositions.size()&&modifiedPositions[mid].first<val)
        mid++;
    return mid;
}
long getMaxGroup(long index){
    if(dp[index]>-1)
        return dp[index];
    long pos=getPos(points[index].first+points[index].second);
    if(pos>=N)
        return 1;
    long nextPoint=getMin(1,0,N-1,pos,N-1);
    dp[index]=1+getMaxGroup(nextPoint);
    return dp[index];
}
*/


#include<stdio.h>
#include<iostream>
#include<string>
#include<cstring>
#include <iomanip>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#include<set>
#include<bitset>
#include<map>
#include<queue>
#include<math.h>
#include <time.h>
using namespace std;
//set<int>::iterator it;
#define mdlo 1000000007
#define maxERR 0.00000002
//#define minVal -10000000000000
#define maxBits 40
#define pi 3.1415926535897932384626433832795
#define INF 999999999999
#define lim 10000007
typedef long long ll;
long long mInv[41];
long long fact[41];
long long factInv[41];
map<long,long>mymap;
typedef pair<ll,ll>skill;
typedef pair<ll,ll>depth;
typedef vector<long>adj;
vector<long>primes;
set<long>candidates;

set<string>dictionary;
set<string>::iterator it;
pair<set<string>::iterator,bool> ret;
string ai,phn;
long len;
bool doesMatch(long pos){
	for(long i=0;i<len;i++){
		if(ai[pos+i]!=phn[i])
			return false;
	}
	return true;
}
long long getmoduloInv(long long n){
    if(n==1)
        return 1;
    if(mInv[n]>0)
        return mInv[n];
    long long m=(-1*mdlo)/n;
    m+=mdlo;
    m*=getmoduloInv(mdlo%n);
    mInv[n]=(m%mdlo);
    return mInv[n];
}
long num[200006],startTingPos[200005];
//ll times[1001006];

vector< long> get_primes(unsigned long max){

    char *sieve;
    sieve = new char[max/8+1];
    // Fill sieve with 1
    long m=(max/8)+1;
    for(long long i=0;i<m;i++)
        sieve[i]=255;
    for(unsigned long x = 2; x <= max; x++)
        if(sieve[x/8] & (0x01 << (x % 8))){
            primes.push_back(x);
            // Is prime. Mark multiplicates.
            for(unsigned long j = 2*x; j <= max; j += x)
                sieve[j/8] &= ~(0x01 << (j % 8));
        }
    delete[] sieve;
    return primes;
}

int main(void){
//  freopen ("E:/inputSmall.txt","r",stdin);
//  freopen ("E:/outputSmall2.txt","w",stdout);
    ll test_cases=1;//,C,D,A,L,R,rep,round=0,rem,num;
   //cin>>test_cases>>r>>v;
    cout << setprecision(15) << fixed;
//	get_primes(32000);
	ll n,k,m,l,r,x;
    cin>>n>>m;
	num[0]=-1;
	for(long i=1;i<=n;i++){
		cin>>num[i];
		if(num[i]==num[i-1])
			startTingPos[i]=startTingPos[i-1];
		else
			startTingPos[i]=i;
	}
	for(long i=0;i<m;i++){
		cin>>l>>r>>x;
		if(num[r]!=x)
			cout<<r<<endl;
		else if(startTingPos[r]>l)
			cout<<startTingPos[r]-1<<endl;
		else
			cout<<-1<<endl;
	}

    return 0;
}
/*ll cumDist1[100005];
ll cumDist2[100005];
vector<ll>distFrom1;
vector<ll>distFrom2;
void initFact(){
    fact[0]=1;
    factInv[0]=1;
    for(ll i=1;i<0;i++){
        factInv[i]=(factInv[i-1]*getmoduloInv(i))%mdlo;
        fact[i]=(fact[i-1]*i)%mdlo;
    }
}
bool isLeapyear(long year){
    if(year%4==0&&(year%100!=0||year%400==0))
        return true;
    return false;
}
ll ds,ms,ys,de,me,ye,dc,mc,yc,day;
void next13th(){
    if(ds<13){
        ds=13;
        return;
    }
    ms++;
    ds=13;
    if(ms>12)
    {
        ms=1;
        ys++;
    }
}
    long months[]={31,28,31,30,31,30,31,31,30,31,30,31};
    long dayBeforeMonth[12];
bool validDate(){
    if(ys>ye)
        return false;
    if(ys<ye)
        return true;
    if(ms>me)
        return false;
    if(ms<me)
        return true;
    if(ds>de)
        return false;
    return true;
}
long getDay(long d,long m,long y){
    long day=((y-1900)*365+(y-1900)/4-(y-1900)/100+(y-1600)/400+dayBeforeMonth[m-1]+d+2)%7;
    if(y%4==0&&m<3){
        if(y%400==0||y%100!=0)
            day=(day+6)%7;
    }
    return day;
}
bool iscurDayFriday(){
    if(getDay(ds,ms,ys)==0)
        return true;
    return false;
}
void dijkstra(long startPoint){
    long m;
    if(startPoint==1)
        m=0;
    else
        m=1;
    distMatrix[m][startPoint]=0;
    priority_queue<edge, vector<edge>,greater <edge>>pq;
    pq.push(edge(0,startPoint));
    while(!pq.empty()){
        edge top=pq.top();
        pq.pop();
        ll d= top.first,u=top.second;
        if(distMatrix[m][u]==d){
            for(long i=0;i<graph[u].size();i++){
                ll v=graph[u][i].second;
                ll ec=graph[u][i].first;
                if(distMatrix[m][v]>distMatrix[m][u]+ec){
                    distMatrix[m][v]=distMatrix[m][u]+ec;
                    pq.push(edge(distMatrix[m][v],v));
                }
            }
        }
    }
}
ll vals[1];
ll dp[1];
ll totalSum[1];
long long mInv[1];
long long fact[1];
long long factInv[1];

//long long pow10[18];
long long getmoduloInv(long long n){
    if(n==1)
        return 1;
    if(mInv[n]>0)
        return mInv[n];
    long long m=(-1*mdlo)/n;
    m+=mdlo;
    m*=getmoduloInv(mdlo%n);
    mInv[n]=(m%mdlo);
    return mInv[n];
}
long long onNthbit(long pos,long val){
    return val|pwr2[pos];
}
bool isNthbitOn(long long pos,long long val){
    return (val&pwr2[pos])>0;
}

seg segTree[5];
long N;
void buildSumSegmentTree(long long b,long long e,long long node){
    if(b==e)
    {
         segTree[node].first=vals[b];
         return;
    }
    long long mid=(b+e)/2;
    buildSumSegmentTree(b,mid,node*2);
    buildSumSegmentTree(mid+1,e,1+(node*2));
    segTree[node].first=segTree[2*node].first+segTree[1+(node*2)].first;
}
long long getSum(long long qStart,long long qEnd,long long sStart,long long sEnd,long long node,prop p){

    long k=sEnd-sStart,n;
    for(long i=0;i<p.size();i++){
        segTree[node].second.push_back(p[i]);
        n=p[i];
        segTree[node].first+=(((n+k)*(n+k+1)*(2*n+2*k+1)-(n*(n-1)*(2*n-1)))/6+((n+k)*(n+k+1)-n*(n-1)))/2;
        }
    if(qEnd<sStart||qStart>sEnd)
    {
        return 0;
    }
    if(sStart>=qStart&&sEnd<=qEnd)
    {
         return segTree[node].first;
    }
    long long sMid=(sStart+sEnd)/2;
    prop l;
    for(long i=0;segTree[node].second.size();i++)
        l.push_back(segTree[node].second[i]+sMid+1-sStart);
    return getSum(qStart,qEnd,sStart,sMid,2*node,segTree[node].second)+getSum(qStart,qEnd,sMid+1,sEnd,1+(2*node),l);
}
long long update(ll node, long long sStart,ll sEnd,long upStart,long upEnd){
    if(upEnd<sStart||upStart>sEnd)
        return 0;
    long k=sEnd-sStart,n=sStart+1-upStart;
    if(upStart<=sStart&&upEnd>=sEnd){
        segTree[node].second.push_back(n);
        segTree[node].first+=(((n+k)*(n+k+1)*(2*n+2*k+1))/6);
        segTree[node].first-=(((n*(n-1)*(2*n-1)))/6);
        segTree[node].first+=(((n+k)*(n+k+1)-n*(n-1)))/2;
        return 0;
    }
    ll sMid=(sStart+sEnd)/2;
    update(node*2,sStart,sMid,upStart,upEnd);
    update(1+(node*2),sMid+1,sEnd,upStart,upEnd);
    segTree[node].first=segTree[2*node].first+segTree[1+(node*2)].first;

    for(long i=0;i<segTree[node].second.size();i++){
        n=segTree[node].second[i];
        segTree[node].first+=(((n+k)*(n+k+1)*(2*n+2*k+1)-(n*(n-1)*(2*n-1)))/6+((n+k)*(n+k+1)-n*(n-1)))/2;
    }
    return segTree[node].first;
}
void update(long x,long y){
    long len=y-x+1,add=0;
    for(long i=0;i<len;i++){
        add+=(i+1)*2;
        update(1,0,N-1,x+i,add+vals[x+i]);
    }
}
long getlen(long long num){
    long len=0;
    while(num>0){
        num/=10;
        len++;
    }
    return len;
}
encryptedLine lineConverter(string s){
    encryptedLine el;
    ll val=0,len=s.size();
    for(long i=0;i<len;i++){
        if(s[i]==' '){
            el.push_back(val);
            val=0;
        }
        else{
            val*=26;
            val+=(s[i]-'a');
        }
    }
    el.push_back(val);
    return el;
}
long getPalinDrome(long num){
    long a=num%10;
    long b=(num/10)%10;
    long c=(num/100)%10;
    return num*1000+a*100+b*10+c;
}

vector<unsigned long> get_primes(unsigned long max){
    vector<unsigned long> primes;
    char *sieve;
    sieve = new char[max/8+1];
    // Fill sieve with 1
    long m=(max/8)+1;
    for(long long i=0;i<m;i++)
        sieve[i]=255;
    for(unsigned long x = 2; x <= max; x++)
        if(sieve[x/8] & (0x01 << (x % 8))){
            primes.push_back(x);
            // Is prime. Mark multiplicates.
            for(unsigned long j = 2*x; j <= max; j += x)
                sieve[j/8] &= ~(0x01 << (j % 8));
        }
    delete[] sieve;
    return primes;
}string add(string a,string b){
    int l1=a.size();
    int l2=b.size();
    while(l1<l2){
        a="0"+a;
        l1++;
    }
    while(l2<l1){
        b="0"+b;
        l2++;
    }
    string s;
    int carry=0;
    for(long i=l2-1;i>-1;i--){
        int d=a[i]+b[i]+carry-2*'0';
        carry=d/10;
        a[i]='0'+(d%10);
    }
    if(carry)
        a="1"+a;
    return a;
}
long long mInv[1010];
long long fact[1000];
long long factInv[1000];
long long getmoduloInv(long long n){
    if(n==1)
        return 1;
    if(mInv[n]>0)
        return mInv[n];
    long long m=(-1*mdlo)/n;
    m+=mdlo;
    m*=getmoduloInv(mdlo%n);
    mInv[n]=(m%mdlo);
    return mInv[n];

}

long dp[200010];
vector<weightedPos>points;
vector<weightedPos>modifiedPositions;
vector<long long>weightPlusPos;
long long segTree[530010];
long N,X,W;
void buildSegTree(long node,long b,long e){
    if(b==e)
        segTree[node]=b;
    else{
        long mid=(b+e)/2;
        buildSegTree(node*2,b,mid);
        buildSegTree(1+node*2,mid+1,e);
        if(weightPlusPos[segTree[node*2]]<=weightPlusPos[segTree[1+node*2]])
            segTree[node]=segTree[node*2];
        else
            segTree[node]=segTree[1+node*2];
    }
}
long long getMin(long node,long segBeg,long segEnd,long qBeg,long qEnd){
    if(segEnd<qBeg||segBeg>qEnd)
        return N;
    if(segBeg>=qBeg&&segEnd<=qEnd)
        return segTree[node];
    long mid=(segBeg+segEnd)/2;
    long fh=getMin(node*2,segBeg,mid,qBeg,qEnd);
    long sh=getMin(1+node*2,mid+1,segEnd,qBeg,qEnd);
    if(weightPlusPos[sh]<weightPlusPos[fh])
        return sh;
    return fh;
}
long long getMinPos(long node,long segBeg,long segEnd,long qBeg,long qEnd){
    if(segEnd<qBeg||segBeg<qEnd)
        return 0;
    if(segBeg>=qBeg&&segEnd<=qEnd)
        return segTree[node];
    long mid=(segBeg+segEnd)/2;
    long fh=getMin(node*2,segBeg,mid,qBeg,qEnd);
    long sh=getMin(node*2,mid+1,segEnd,qBeg,qEnd);
    return min(fh,sh);
}
long getPos(long val){
    long low=0,high=modifiedPositions.size()-1;
    long mid=(low+high)/2;
    while(low<high){
        if(modifiedPositions[mid].first<val)
            low=mid+1;
        else
            high=mid-1;
        mid=(low+high)/2;
    }
    if(mid>0)
        mid--;
    while(mid<modifiedPositions.size()&&modifiedPositions[mid].first<val)
        mid++;
    return mid;
}
long getMaxGroup(long index){
    if(dp[index]>-1)
        return dp[index];
    long pos=getPos(points[index].first+points[index].second);
    if(pos>=N)
        return 1;
    long nextPoint=getMin(1,0,N-1,pos,N-1);
    dp[index]=1+getMaxGroup(nextPoint);
    return dp[index];
}
*/


#include<stdio.h>
#include<iostream>
#include<string>
#include<cstring>
#include <iomanip>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#include<set>
#include<bitset>
#include<map>
#include<queue>
#include<math.h>
#include <time.h>
using namespace std;
//set<int>::iterator it;
#define mdlo 1000000007
#define maxERR 0.00000002
//#define minVal -10000000000000
#define maxBits 40
#define pi 3.1415926535897932384626433832795
#define INF 999999999999
#define lim 10000007
typedef long long ll;
long long mInv[41];
long long fact[41];
long long factInv[41];
map<long,long>mymap;
typedef pair<ll,ll>skill;
typedef pair<ll,ll>depth;
typedef vector<long>adj;
vector<long>primes;
set<long>candidates;

set<string>dictionary;
set<string>::iterator it;
pair<set<string>::iterator,bool> ret;
string ai,phn;
long len;
bool doesMatch(long pos){
	for(long i=0;i<len;i++){
		if(ai[pos+i]!=phn[i])
			return false;
	}
	return true;
}
long long getmoduloInv(long long n){
    if(n==1)
        return 1;
    if(mInv[n]>0)
        return mInv[n];
    long long m=(-1*mdlo)/n;
    m+=mdlo;
    m*=getmoduloInv(mdlo%n);
    mInv[n]=(m%mdlo);
    return mInv[n];
}
long num[200006],startTingPos[200005];
//ll times[1001006];

vector< long> get_primes(unsigned long max){

    char *sieve;
    sieve = new char[max/8+1];
    // Fill sieve with 1
    long m=(max/8)+1;
    for(long long i=0;i<m;i++)
        sieve[i]=255;
    for(unsigned long x = 2; x <= max; x++)
        if(sieve[x/8] & (0x01 << (x % 8))){
            primes.push_back(x);
            // Is prime. Mark multiplicates.
            for(unsigned long j = 2*x; j <= max; j += x)
                sieve[j/8] &= ~(0x01 << (j % 8));
        }
    delete[] sieve;
    return primes;
}

int main(void){
//  freopen ("E:/inputSmall.txt","r",stdin);
//  freopen ("E:/outputSmall2.txt","w",stdout);
    ll test_cases=1;//,C,D,A,L,R,rep,round=0,rem,num;
   //cin>>test_cases>>r>>v;
    cout << setprecision(15) << fixed;
//	get_primes(32000);
	ll n,k,m,l,r,x;
    cin>>n>>m;
	num[0]=-1;
	for(long i=1;i<=n;i++){
		cin>>num[i];
		if(num[i]==num[i-1])
			startTingPos[i]=startTingPos[i-1];
		else
			startTingPos[i]=i;
	}
	for(long i=0;i<m;i++){
		cin>>l>>r>>x;
		if(num[r]!=x)
			cout<<r<<endl;
		else if(startTingPos[r]>l)
			cout<<num[startTingPos[r]-1]<<endl;
		else
			cout<<-1<<endl;
	}

    return 0;
}
/*ll cumDist1[100005];
ll cumDist2[100005];
vector<ll>distFrom1;
vector<ll>distFrom2;
void initFact(){
    fact[0]=1;
    factInv[0]=1;
    for(ll i=1;i<0;i++){
        factInv[i]=(factInv[i-1]*getmoduloInv(i))%mdlo;
        fact[i]=(fact[i-1]*i)%mdlo;
    }
}
bool isLeapyear(long year){
    if(year%4==0&&(year%100!=0||year%400==0))
        return true;
    return false;
}
ll ds,ms,ys,de,me,ye,dc,mc,yc,day;
void next13th(){
    if(ds<13){
        ds=13;
        return;
    }
    ms++;
    ds=13;
    if(ms>12)
    {
        ms=1;
        ys++;
    }
}
    long months[]={31,28,31,30,31,30,31,31,30,31,30,31};
    long dayBeforeMonth[12];
bool validDate(){
    if(ys>ye)
        return false;
    if(ys<ye)
        return true;
    if(ms>me)
        return false;
    if(ms<me)
        return true;
    if(ds>de)
        return false;
    return true;
}
long getDay(long d,long m,long y){
    long day=((y-1900)*365+(y-1900)/4-(y-1900)/100+(y-1600)/400+dayBeforeMonth[m-1]+d+2)%7;
    if(y%4==0&&m<3){
        if(y%400==0||y%100!=0)
            day=(day+6)%7;
    }
    return day;
}
bool iscurDayFriday(){
    if(getDay(ds,ms,ys)==0)
        return true;
    return false;
}
void dijkstra(long startPoint){
    long m;
    if(startPoint==1)
        m=0;
    else
        m=1;
    distMatrix[m][startPoint]=0;
    priority_queue<edge, vector<edge>,greater <edge>>pq;
    pq.push(edge(0,startPoint));
    while(!pq.empty()){
        edge top=pq.top();
        pq.pop();
        ll d= top.first,u=top.second;
        if(distMatrix[m][u]==d){
            for(long i=0;i<graph[u].size();i++){
                ll v=graph[u][i].second;
                ll ec=graph[u][i].first;
                if(distMatrix[m][v]>distMatrix[m][u]+ec){
                    distMatrix[m][v]=distMatrix[m][u]+ec;
                    pq.push(edge(distMatrix[m][v],v));
                }
            }
        }
    }
}
ll vals[1];
ll dp[1];
ll totalSum[1];
long long mInv[1];
long long fact[1];
long long factInv[1];

//long long pow10[18];
long long getmoduloInv(long long n){
    if(n==1)
        return 1;
    if(mInv[n]>0)
        return mInv[n];
    long long m=(-1*mdlo)/n;
    m+=mdlo;
    m*=getmoduloInv(mdlo%n);
    mInv[n]=(m%mdlo);
    return mInv[n];
}
long long onNthbit(long pos,long val){
    return val|pwr2[pos];
}
bool isNthbitOn(long long pos,long long val){
    return (val&pwr2[pos])>0;
}

seg segTree[5];
long N;
void buildSumSegmentTree(long long b,long long e,long long node){
    if(b==e)
    {
         segTree[node].first=vals[b];
         return;
    }
    long long mid=(b+e)/2;
    buildSumSegmentTree(b,mid,node*2);
    buildSumSegmentTree(mid+1,e,1+(node*2));
    segTree[node].first=segTree[2*node].first+segTree[1+(node*2)].first;
}
long long getSum(long long qStart,long long qEnd,long long sStart,long long sEnd,long long node,prop p){

    long k=sEnd-sStart,n;
    for(long i=0;i<p.size();i++){
        segTree[node].second.push_back(p[i]);
        n=p[i];
        segTree[node].first+=(((n+k)*(n+k+1)*(2*n+2*k+1)-(n*(n-1)*(2*n-1)))/6+((n+k)*(n+k+1)-n*(n-1)))/2;
        }
    if(qEnd<sStart||qStart>sEnd)
    {
        return 0;
    }
    if(sStart>=qStart&&sEnd<=qEnd)
    {
         return segTree[node].first;
    }
    long long sMid=(sStart+sEnd)/2;
    prop l;
    for(long i=0;segTree[node].second.size();i++)
        l.push_back(segTree[node].second[i]+sMid+1-sStart);
    return getSum(qStart,qEnd,sStart,sMid,2*node,segTree[node].second)+getSum(qStart,qEnd,sMid+1,sEnd,1+(2*node),l);
}
long long update(ll node, long long sStart,ll sEnd,long upStart,long upEnd){
    if(upEnd<sStart||upStart>sEnd)
        return 0;
    long k=sEnd-sStart,n=sStart+1-upStart;
    if(upStart<=sStart&&upEnd>=sEnd){
        segTree[node].second.push_back(n);
        segTree[node].first+=(((n+k)*(n+k+1)*(2*n+2*k+1))/6);
        segTree[node].first-=(((n*(n-1)*(2*n-1)))/6);
        segTree[node].first+=(((n+k)*(n+k+1)-n*(n-1)))/2;
        return 0;
    }
    ll sMid=(sStart+sEnd)/2;
    update(node*2,sStart,sMid,upStart,upEnd);
    update(1+(node*2),sMid+1,sEnd,upStart,upEnd);
    segTree[node].first=segTree[2*node].first+segTree[1+(node*2)].first;

    for(long i=0;i<segTree[node].second.size();i++){
        n=segTree[node].second[i];
        segTree[node].first+=(((n+k)*(n+k+1)*(2*n+2*k+1)-(n*(n-1)*(2*n-1)))/6+((n+k)*(n+k+1)-n*(n-1)))/2;
    }
    return segTree[node].first;
}
void update(long x,long y){
    long len=y-x+1,add=0;
    for(long i=0;i<len;i++){
        add+=(i+1)*2;
        update(1,0,N-1,x+i,add+vals[x+i]);
    }
}
long getlen(long long num){
    long len=0;
    while(num>0){
        num/=10;
        len++;
    }
    return len;
}
encryptedLine lineConverter(string s){
    encryptedLine el;
    ll val=0,len=s.size();
    for(long i=0;i<len;i++){
        if(s[i]==' '){
            el.push_back(val);
            val=0;
        }
        else{
            val*=26;
            val+=(s[i]-'a');
        }
    }
    el.push_back(val);
    return el;
}
long getPalinDrome(long num){
    long a=num%10;
    long b=(num/10)%10;
    long c=(num/100)%10;
    return num*1000+a*100+b*10+c;
}

vector<unsigned long> get_primes(unsigned long max){
    vector<unsigned long> primes;
    char *sieve;
    sieve = new char[max/8+1];
    // Fill sieve with 1
    long m=(max/8)+1;
    for(long long i=0;i<m;i++)
        sieve[i]=255;
    for(unsigned long x = 2; x <= max; x++)
        if(sieve[x/8] & (0x01 << (x % 8))){
            primes.push_back(x);
            // Is prime. Mark multiplicates.
            for(unsigned long j = 2*x; j <= max; j += x)
                sieve[j/8] &= ~(0x01 << (j % 8));
        }
    delete[] sieve;
    return primes;
}string add(string a,string b){
    int l1=a.size();
    int l2=b.size();
    while(l1<l2){
        a="0"+a;
        l1++;
    }
    while(l2<l1){
        b="0"+b;
        l2++;
    }
    string s;
    int carry=0;
    for(long i=l2-1;i>-1;i--){
        int d=a[i]+b[i]+carry-2*'0';
        carry=d/10;
        a[i]='0'+(d%10);
    }
    if(carry)
        a="1"+a;
    return a;
}
long long mInv[1010];
long long fact[1000];
long long factInv[1000];
long long getmoduloInv(long long n){
    if(n==1)
        return 1;
    if(mInv[n]>0)
        return mInv[n];
    long long m=(-1*mdlo)/n;
    m+=mdlo;
    m*=getmoduloInv(mdlo%n);
    mInv[n]=(m%mdlo);
    return mInv[n];

}

long dp[200010];
vector<weightedPos>points;
vector<weightedPos>modifiedPositions;
vector<long long>weightPlusPos;
long long segTree[530010];
long N,X,W;
void buildSegTree(long node,long b,long e){
    if(b==e)
        segTree[node]=b;
    else{
        long mid=(b+e)/2;
        buildSegTree(node*2,b,mid);
        buildSegTree(1+node*2,mid+1,e);
        if(weightPlusPos[segTree[node*2]]<=weightPlusPos[segTree[1+node*2]])
            segTree[node]=segTree[node*2];
        else
            segTree[node]=segTree[1+node*2];
    }
}
long long getMin(long node,long segBeg,long segEnd,long qBeg,long qEnd){
    if(segEnd<qBeg||segBeg>qEnd)
        return N;
    if(segBeg>=qBeg&&segEnd<=qEnd)
        return segTree[node];
    long mid=(segBeg+segEnd)/2;
    long fh=getMin(node*2,segBeg,mid,qBeg,qEnd);
    long sh=getMin(1+node*2,mid+1,segEnd,qBeg,qEnd);
    if(weightPlusPos[sh]<weightPlusPos[fh])
        return sh;
    return fh;
}
long long getMinPos(long node,long segBeg,long segEnd,long qBeg,long qEnd){
    if(segEnd<qBeg||segBeg<qEnd)
        return 0;
    if(segBeg>=qBeg&&segEnd<=qEnd)
        return segTree[node];
    long mid=(segBeg+segEnd)/2;
    long fh=getMin(node*2,segBeg,mid,qBeg,qEnd);
    long sh=getMin(node*2,mid+1,segEnd,qBeg,qEnd);
    return min(fh,sh);
}
long getPos(long val){
    long low=0,high=modifiedPositions.size()-1;
    long mid=(low+high)/2;
    while(low<high){
        if(modifiedPositions[mid].first<val)
            low=mid+1;
        else
            high=mid-1;
        mid=(low+high)/2;
    }
    if(mid>0)
        mid--;
    while(mid<modifiedPositions.size()&&modifiedPositions[mid].first<val)
        mid++;
    return mid;
}
long getMaxGroup(long index){
    if(dp[index]>-1)
        return dp[index];
    long pos=getPos(points[index].first+points[index].second);
    if(pos>=N)
        return 1;
    long nextPoint=getMin(1,0,N-1,pos,N-1);
    dp[index]=1+getMaxGroup(nextPoint);
    return dp[index];
}
*/


#include <stdio.h>

int main()
{
	int n, m;
	scanf("%i %i", &n, &m);
	int *arr = new int[n];
	int *mask = new int[n];
	for (int i = 0; i < n; ++i)
	{
		scanf("%i", &arr[i]);
		if (i == 0)
			mask[i] = 0;
		else
		{
			if (arr[i] == arr[i - 1])
				mask[i] = mask[i - 1];
			else
				mask[i] = i - 1;
		}
	}
	for (int i = 0; i < m; ++i)
	{
		int left, right, x;
		scanf("%i %i %i", &left, &right, &x);
		--right;
		--left;
		if (arr[right] != x)
			printf("%i\n", right + 1);
		else if (arr[mask[right]] != x && mask[right] >= left)
			printf("%i\n", mask[right] + 1);
		else
			printf("-1\n");
	}
	delete []arr;
	delete []mask;
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	int *arr = new int[n];
	int *mask = new int[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> arr[i];
		if (i == 0)
			mask[i] = 0;
		else
		{
			if (arr[i] == arr[i - 1])
				mask[i] = mask[i - 1];
			else
				mask[i] = i - 1;
		}
	}
	for (int i = 0; i < m; ++i)
	{
		int left, right, x;
		cin >> left >> right >> x;
		--right;
		--left;
		if (arr[right] != x)
			cout << right + 1 << "\n";
		else if (arr[mask[right]] != x && mask[right] >= left)
			cout << mask[right] + 1 << "\n";
		else
			cout << -1 << "\n";
	}
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	int *arr = new int[n];
	int *mask = new int[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> arr[i];
		if (i == 0)
			mask[i] = 0;
		else
		{
			if (arr[i] == arr[i - 1])
				mask[i] = mask[i - 1];
			else
				mask[i] = i - 1;
		}
	}
	for (int i = 0; i < m; ++i)
	{
		int left, right, x;
		cin >> left >> right >> x;
		--right;
		--left;
		if (arr[right] != x)
			cout << right + 1;
		else if (arr[mask[right]] != x && mask[right] >= left)
			cout << mask[right] + 1;
		else
			cout << -1;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <string>

using namespace std;

	int n, m;
	vector <int> arr;
	vector < pair <int, int> > segTree;

void buildTree(int lf, int rg, int cell)
{
	if (lf == rg)
	{
		segTree[cell].first = lf;
		return;
	}

	int middle = lf + (rg - lf) / 2;
	buildTree(lf, middle, cell * 2 + 1);
	buildTree(middle + 1, rg, cell * 2 + 2);

	segTree[cell].first = segTree[cell * 2 + 1].first;

	if (segTree[cell * 2 + 1].second != -1)
	{
		segTree[cell] = segTree[cell * 2 + 1];
		return;
	}

	if (arr[segTree[cell].first] != arr[segTree[cell * 2 + 2].first])
	{
		segTree[cell].second = segTree[cell * 2 + 2].first;
		return;
	}

	if (segTree[cell * 2 + 2].second != -1 &&
		arr[segTree[cell].first] != arr[segTree[cell * 2 + 2].second])
	{
		segTree[cell].second = segTree[cell * 2 + 2].second;
		return;
	}
}

	bool flag;

void require(int lf, int rg, int a, int b, int cell, int x, int& answer)
{
	if (a > b || flag)
	{
		return;
	}

	if (lf == a && rg == b)
	{
		if (arr[segTree[cell].first] != x)
		{
			flag = true;
			answer = segTree[cell].first;
			return;
		}

		if (segTree[cell].second != -1)
		{
			flag = true;
			answer = segTree[cell].second;
			return;
		}

		return;
	}

	int middle = lf + (rg - lf) / 2;
	require(lf, middle, a, min(b, middle), cell * 2 + 1, x, answer);
	require(middle + 1, rg, max(a, middle + 1), b, cell * 2 + 2, x, answer);
}

int main()
{
	//freopen("input.txt", "r", stdin);

	cin >> n >> m;

	arr.resize(n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]);
	}

	segTree.resize(4 * n, make_pair(-1, -1));
	buildTree(0, n - 1, 0);

	for (int z = 0; z < m; z++)
	{
		int l, r, x;
		scanf("%d%d%d", &l, &r, &x);
		l--;
		r--;

		int answer = -2;
		flag = false;
		require(0, n - 1, l, r, 0, x, answer);

		printf("%d\n", answer + 1);
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <string>

using namespace std;

	vector <int> alpha[1000001];

int main()
{
	//freopen("input.txt", "r", stdin);

	int n, m;
	cin >> n >> m;

	vector <int> arr(n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]);
		alpha[arr[i]].push_back(i);
	}

	for (int z = 0; z < m; z++)
	{
		int l, r, x;
		scanf("%d%d%d", &l, &r, &x);
		l--;
		r--;

		int left = lower_bound(alpha[x].begin(), alpha[x].end(), l)
			- alpha[x].begin();

		if (left == alpha[x].size() || alpha[x][left] > l)
		{
			printf("%d\n", l + 1);
			continue;
		}

		int right = lower_bound(alpha[x].begin(), alpha[x].end(), r)
			- alpha[x].begin();
		if (right == alpha[x].size() || alpha[x][right] > r)
		{
			printf("%d\n", r + 1);
			continue;
		}

		if (r - l == right - left)
		{
			printf("-1\n");
			continue;
		}

		int lf = left;
		int rg = right;
		while (rg - lf > 1)
		{
			int middle = lf + (rg - lf) / 2;
			if (alpha[x][middle] - alpha[x][lf] > middle - lf)
			{
				rg = middle;
			}
			else
			{
				lf = middle;
			}
		}

		printf("%d\n", lf + 2);
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	int n, m;
	cin >> n >> m;

	vector <int> arr(n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]);
	}

	vector <int> dp(n);
	dp[0] = 1;
	for (int i = 1; i < n; i++)
	{
		if (arr[i] != arr[i - 1])
		{
			dp[i] = 1;
		}
		else
		{
			dp[i] = dp[i - 1] + 1;
		}
	}

	for (int z = 0; z < m; z++)
	{
		int lf, rg, x;
		scanf("%d%d%d", &lf, &rg, &x);
		lf--;
		rg--;

		int answer = -2;
		if (arr[rg] != x)
		{
			answer = rg;
		}
		else
		{
			if (rg - dp[rg] >= lf)
			{
				answer = rg - dp[rg];
			}
		}

		printf("%d\n", answer + 1);
	}

	return 0;
}


// rc.cpp : Defines the entry point for the console application.
//

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <functional>

#define PI 3.14159265358979323846

using namespace std;

typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long long uint64;
typedef long long sint64;

int main(int argc, char* argv[])
{
    uint n, m;
    cin >> n >> m;

    map<uint64, vector<pair<uint, uint>>> v;

    uint ip = 0;
    uint64 p = -1,
           a = 0;

    cin >> p;
    for (uint i = 1; i <= n; ++i)
    {
        if (i < n)
            cin >> a;

        if (i == n || a != p)
        {
            pair<uint, uint> z(ip, i - 1);
            v[p].push_back(z);
            ip = i;
        }

        p = a;
    }

    for (uint i = 0; i < m; ++i)
    {
        uint l, r;
        uint64 x;
        cin >> l >> r >> x;

        map<uint64, vector<pair<uint, uint>>>::iterator it = v.find(x);
        if (it == v.end())
            printf("%u\n", l);
        else
        {
            --l, --r;
            vector<pair<uint, uint>>& qv = it->second;
            vector<pair<uint, uint>>::iterator jt = lower_bound(qv.begin(), qv.end(), make_pair(l, (uint)0));
            if (jt == qv.end())
                printf("%u\n", l + 1);
            else if (jt->first <= l && jt->second >= r)
                printf("-1\n");
            else
            {
                if (jt->first > l)
                    printf("%u\n", l + 1);
                else
                    printf("%u\n", jt->second + 2);
            }
        }
    }

    return 0;
}