process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    C();
});

function readline() {
    return inputString[currentLine++];
}

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n,m] = ti(readline().split(' '));
        let mat = new Array(n);
        let dp = new Array(n);
        for(let i = 0; i < n; i++){
            dp[i] = new Array(m);
            dp[i].fill(0);
        }

        for(let i = 0; i < n; i++){
            mat[i] = ti(readline().split(' '));
        }

        let len = n+m-2;
        let level = 0;
        let q = [[0,0],[n-1,m-1],null];
        let count = 0;
        let c1 = 0;
        let c0 = 0;
        let isValid = (r,c) => {
            if(r < 0 || r >= n || c < 0 || c >= m) return false;
            if(dp[r][c] === 1) return false;
            return true;
        }

        while(q.length > 0){
            let node = q.shift();
            if(node !== null){
                dp[node[0]][node[1]] = 1;
                if(mat[node[0]][node[1]] === 0) c0+=1;
                if(mat[node[0]][node[1]] === 1) c1+=1;
                if(isValid(node[0]+1, node[1])){
                    dp[node[0]+1][node[1]] = 1;
                    q.push([node[0]+1,node[1]]);
                }
                if(isValid(node[0], node[1]+1)){
                    dp[node[0]][node[1]+1] = 1;
                    q.push([node[0],node[1]+1]);
                }
                if(isValid(node[0]-1,node[1])){
                    dp[node[0]-1][node[1]] = 1;
                    q.push([node[0]-1, node[1]]);
                }
                if(isValid(node[0], node[1]-1)){
                    dp[node[0]][node[1]-1] = 1;
                    q.push([node[0], node[1]-1]);
                }
            }else{
                if(level !== Math.ceil(len/2)){
                    if(c1 !== 0 && c0 !== 0)
                        count += Math.min(c1,c0);
                }
                level += 1;
                c1 = c0 = 0;
                if(q.length !== 0)
                    q.push(null);
            }
        }

        console.log(count);
    }
}

function solv() {
    var ip = readline().split(' ').map(x => parseInt(x))
    var x = ip[0]
    var y = ip[1]
    var s = []
    for (var n = 0; n < x; n++) {
        s.push(readline().split(' ').map(x => parseInt(x)))
    }
    var res = 0;

    var v1 = new Array(x + y);
    var v2 = new Array(x + y);;
    v1.fill(0)
    v2.fill(0)
    for (var n = 0; n < x; n++) {
        for (var k = 0; k < y; k++) {
            if (s[n][k] == 1) {
                if (v1[n + k] == null) v1[n + k] = 1
                else v1[n + k]++;
            }
            else {
                if (v2[n + k] == null) v2[n + k] = 1
                else v2[n + k]++;
            }
        }
    }
    var len = x + y - 2;
    var j = (x % 2 == y % 2)
    for (var n = 0; n <= Math.floor((len) / 2) - j; n++) {
        if (n != len - n) {
            res += Math.min(v1[n] + v1[len - n], v2[n] + v2[len - n]);
            var d = v1[n] + v1[len - n]
            var e = v2[n] + v2[len - n]
        }
        else res += Math.min(v1[n], v2[n]);
    }

    print(res)
}

var tc = 1;
tc = parseInt(readline())
while (tc--) solv()

// var lineIdx = 0;
// var readline = () => {
//   var input = ["4", "2 2", "1 1", "0 1", "2 3", "1 1 0", "1 0 0", "3 7", "1 0 1 1 1 1 1", "0 0 0 0 0 0 0", "1 1 1 1 1 0 1", "3 5", "1 0 1 0 0", "1 1 1 1 0", "0 0 1 0 0"]
//   return input[lineIdx++];
// };
// var print = (str) => {
//   console.log(str);
// };

var t = readline().split(" ").map(function(x) { return parseInt(x); })[0];

var step = () => {
  var input = readline().split(" ").map(function(x) { return parseInt(x); });
  var n = input[0];
  var m = input[1];

  var matrix = new Array();

  for(var i = 0; i <n; i++){
    var row = readline().split(" ").map(function(x) { return parseInt(x); });
    matrix.push(row);
  }

  var path = new Array()

  for(var k = 0; k < n+m; k++){
    path[k] = {zero: 0, one: 0};
  }

  var res = 0;
  var half = Math.floor((n+m-2)/2);
  for(var i = 0; i < n; i ++){
    for(var j = 0; j < m; j++){
      if((n + m) % 2 == 0 && i + j == half) {
        continue;
      }
      // if(matrix[i][j] != matrix[n-1 - i][m-1 -j]){
      //   res += 1
      // }

      if(matrix[i][j] == 0){
        path[i+j].zero += 1
      }
      else{
        path[i+j].one += 1
      }
    }
  }

  for(var r = 0; r <=half; r++){
    var one = path[r].one + path[n+m-2-r].one;
    var zero = path[r].zero + path[n+m-2-r].zero;
    res += Math.min(one, zero);
  }

  print(res)

}

for(var i2 = 0; i2 < t; i2++){
  step();
}


var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();
		const b = rna();

		const cost = [];
		for (let i = 0; i < n; i++) {
			let cur = b[i];
			while (cur > 0 && cost[cur] == undefined) {
				cost[cur] = i;
				cur--;
			}
		}

		let ans = 1e9;
		for (let i = 0; i < n; i++) {
			ans = Math.min(ans, i + cost[a[i]]);
		}

		console.log(ans);
	}
}

const nextString = (function() {
  const listeners = [], strings = [], ps = process.stdin
  let last = ''
  ps.setEncoding('utf8')
  ps.on('readable', () => {
    let chunk
    while ((chunk = ps.read()) !== null) {
      chunk = (last + chunk).split(/\r\n|\r|\n/)
      last = chunk[chunk.length - 1]
      for (let i = 0; i < chunk.length - 1; ++i) {
        if (chunk[i].length > 0) {
          if (listeners.length > 0) {
            listeners.shift()(chunk[i])
          }
          else {
            strings.push(chunk[i])
          }
        }
      }
    }
  })
  const fn = resolve => {
    if (strings.length > 0) {
      resolve(strings.shift())
    }
    else {
      listeners.push(resolve)
    }
  }
  return () => new Promise(fn)
})()

async function main() {
  let t = +await nextString()
  for (let iii = 0; iii < t; ++iii) {
    let n = +await nextString()
    let mas1 = (await nextString()).split(' ').map(x => +x)
    let mas2 = (await nextString()).split(' ').map(x => +x)
    let a = [[mas1[0], 0]]
    let b = [[mas2[0], 0]]
    for (let i = 1; i < n; ++i) {
      if (mas1[i] < a[a.length - 1][0]) {
        a.push([mas1[i], i])
      }
      if (mas2[i] > b[b.length - 1][0]) {
        b.push([mas2[i], i])
      }
    }
    let ans = +Infinity
    n = a.length - 1
    m = 0
    while (n >= 0 && m < b.length) {
      ans = Math.min(ans, a[n][1] + b[m][1])
      if (n > 0 && a[n - 1][0] < b[m][0]) {
        --n
      }
      else {
        ++m
      }
    }
    console.log(ans)
  }
}

main()

/*
3
2
3 1
4 2
3
5 3 1
2 4 6
5
7 5 9 1 3
2 4 6 10 8
*/

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();
		const b = rna();

		let i = 0;
		while (a[i] > b[0]) i++;

		let j = 0;
		while (b[j] < a[0]) j++;

		ans = Math.min(i, j);

		console.log(ans);
	}
}


;(function () {

	print(function (n) {

		var v = readline().split(' ').map(Number);

		var v_type1 = [0];
		for (var i = 0; i < n; i++) v_type1.push(v_type1[i] + v[i]);

		v = v.sort(function (a, b) { return a - b; });
		var v_type2 = [0];
		for (var i = 0; i < n; i++) v_type2.push(v_type2[i] + v[i]);

		var m = +readline();

		var questions = [];
		while (m--) {
			questions.push(readline().split(' ').map(Number));
		} m = questions.length;

		return questions.map(function (e) {
			return e[0] === 1 ? (v_type1[e[2]] - v_type1[e[1] - 1]) : (v_type2[e[2]] - v_type2[e[1] - 1]);
		}).join('\n');

	}(+readline()));

}.call(this));

var lenArr = readline().split(' ').map(Number);
var ArrNormal = readline().split(' ').map(Number);
var numQue = readline().split(' ').map(Number);
var queArr = [];
var sumArrN = [];
var sumArrS = [];
var ArrSort = ArrNormal.slice().sort(function(a,b){return a-b;});
sumArrN[0] = ArrNormal[0];
sumArrS[0] = ArrSort[0];
for (var t=1; t<lenArr; t++) {
    sumArrN[t]= sumArrN[t-1] + ArrNormal[t];
    sumArrS[t]= sumArrS[t-1] + ArrSort[t];
}
for (var i=0; i<numQue; i++) {
    var summ = 0;
    queArr[i] = readline().split(' ').map(Number);
    if (queArr[i][0] == 1) {
        if (queArr[i][1] == 1) {
            summ = summ = sumArrN[queArr[i][2]-1];
        }
        else {
            summ = sumArrN[queArr[i][2]-1] - sumArrN[queArr[i][1]-2];
        }
    }
    else {
        if (queArr[i][1] == 1) {
            summ = sumArrS[queArr[i][2]-1];
        }
        else {
            summ = sumArrS[queArr[i][2]-1] - sumArrS[queArr[i][1]-2];
        }
    }
    print(summ);
}

function check (index1,index2,arr)
{
	if (index1-2 >=0 && index2-1 >=0){
		return arr[index2-1] - arr[index1-2];
	}
	else{
		return arr[index2-1];
	}
}
// Acquiring the input
var discard = readline();
var arr2 = readline().split(' ').map((val)=>{
	return parseInt(val);
}), arr1 = [...arr2], sum1 = 0;
var questions = parseInt(readline());
// Preprocessing
arr2.sort((a,b)=>{return a-b}).reduce((sum2,val,index,arr2)=>{
	sum1+=arr1[index];
	arr1[index] = sum1;
	sum2 += arr2[index];
	arr2[index] = sum2;
	return sum2;
},0)
// Answering queries
for(var i = 0 ; i < questions; i++){
	var info = readline().split(' ').map((val)=>{
		return parseInt(val);
	})
	if (info[0] == 1){
		print(check(info[1],info[2],arr1));
	}
	else{
		print(check(info[1],info[2],arr2));
	}
}

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var n = parseInt(readline()),
		stones = tokenizeIntegers(readline()), sorted = new Array(n),
		sumStones = [0], sumSorted = [0],
		qNum = parseInt(readline());
	for (var i = 0; i < n; ++i) {
		sorted[i] = stones[i];
	}
	sorted.sort(function (a, b) {
		return a-b;
	});
	for (var i = 0; i < n; ++i) {
		sumStones.push(sumStones[i]+stones[i]);
		sumSorted.push(sumSorted[i]+sorted[i]);
	}
	for (var i = 0; i < qNum; ++i) {
		var query = tokenizeIntegers(readline());
		if (query[0] == 1) {
			print(sumStones[query[2]]-sumStones[query[1]-1]);
		} else {
			print(sumSorted[query[2]]-sumSorted[query[1]-1]);
		}
	}
}

main();

var n = parseInt(readline()),
	vArr = readline().split(/\s/), vSum = getCumulativeSum(vArr),
	uArr = vArr.sort(function(a, b)	{ return a - b }), uSum = getCumulativeSum(uArr),
	m = parseInt(readline());

for(var index = 0; index < m; index++)	{
	var inputs = readline().split(/\s/).map(Number),
		type = inputs[0], l = inputs[1], r = inputs[2];

	print(type == 1 ? vSum[r] - vSum[l - 1] : uSum[r] - uSum[l - 1]);
}

function getCumulativeSum(arr)	{
	var cumulativeSum = [ 0 ];

	arr = arr.map(function(a, index)	{
		a = parseInt(a);

		cumulativeSum.push(cumulativeSum[cumulativeSum.length - 1] + a);

		return a;
	});

	return cumulativeSum;
};

const lines = [];

const helpers = {
  arrStringtoInt: (arr, splitter) => {
    return arr.split(splitter).map(num => parseInt(num));
  },
  insterAt: (arr, idx, item) => {
    const newArray = [...arr];
    newArray.splice(idx, 0, item);
    return newArray;
  },
  sortAscending: (arr) => {
    return arr.sort((a, b) => a - b);
  },
  sortDescending(arr) {
    return arr.sort((a, b) => b - a);
  }
}

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

// multi line input
readline.on('line', line => {
  lines.push(line);
});

readline.on('close', line => {
  const numbers = helpers.arrStringtoInt(lines[1], ' ');
  const rangeSum1 = [0];
  const rangeSum2 = [0];

  // Get the first range sum of type 1 O(n)
  for (let ii = 0; ii < numbers.length; ii++) {
    rangeSum1.push(numbers[ii] + rangeSum1[ii]);
  }

  // O(nlogn)
  numbers.sort((a, b) => a - b);

  // Get the first range sum of type 2 O(n)
  for (let ii = 0; ii < numbers.length; ii++) {
    rangeSum2.push(numbers[ii] + rangeSum2[ii]);
  }

  // Answer the questions in O(m);
  for (let ii = 3; ii < lines.length; ii++) {
    const inputs = helpers.arrStringtoInt(lines[ii], ' ');
    const t = inputs[0], l = inputs[1], r = inputs[2];
    const arr = t == 1 ? rangeSum1 : rangeSum2;
    console.log(arr[r] - arr[l - 1])
  }
});

/**
 *
Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n.
The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:

She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .
Let ui be the cost of the i-th cheapest stone (the cost that will be on the i-th place if we arrange all the stone costs in non-decreasing order).
This time she will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .
For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.

Input
The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n integers: v1, v2, ..., vn (1 ≤ vi ≤ 109) — costs of the stones.

The third line contains an integer m (1 ≤ m ≤ 105) — the number of Kuriyama Mirai's questions. Then follow m lines, each line contains three integers type,
 l and r (1 ≤ l ≤ r ≤ n; 1 ≤ type ≤ 2), describing a question. If type equal to 1, then you should output the answer for the first question,
 else you should output the answer for the second one.

Output
Print m lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.

[ 6, 10, 12, 19, 21, 28 ]

[ 2, 4, 8, 14, 21, 28 ]

Examples
input
6
6 4 2 7 2 7
3
2 3 6
1 3 4
1 1 6
output
24
9
28
input
4
5 5 2 3
10
1 2 4
2 1 4
1 1 1
2 1 4
2 1 2
1 1 1
1 3 3
1 1 3
1 4 4
1 2 2
output
10
15
5
15
5
5
2
12
3
5
 */

let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    let lenthOfInput = Number(inputString[0])
    let input = inputString[1].split(" ");
    let lengthOfQuestion = Number(inputString[2])
    let questions = inputString.slice(3)

    solution(lenthOfInput, input, lengthOfQuestion, questions);

});

function solution(lenthOfInput, input, lengthOfQuestion, questions) {

    let perfixSum = [];
    let sortedPerfixSum = [];
    let solutionArray = [];

    for (let index = 0; index < lenthOfInput; index++) {

        perfixSum[index] = (perfixSum[index - 1] ? perfixSum[index - 1] : 0) + Number(input[index])
    }

    input.sort(function (current, next) {
        return current - next;
    })

    for (let index = 0; index < lenthOfInput; index++) {

        sortedPerfixSum[index] = (sortedPerfixSum[index - 1] ? sortedPerfixSum[index - 1] : 0) + Number(input[index])
    }

    for (let index = 0; index < lengthOfQuestion; index++) {

        let question = Number(questions[index].split(" ")[0]);
        let left = Number(questions[index].split(" ")[1])
        let right = Number(questions[index].split(" ")[2])
        let solution;

        if (question == 1)

            solution = perfixSum[right - 1] - (perfixSum[left - 2] ? perfixSum[left - 2] : 0)
        else
            solution = sortedPerfixSum[right - 1] - (sortedPerfixSum[left - 2] ? sortedPerfixSum[left - 2] : 0)

        solutionArray.push(solution);
        solutionArray.push("\n")

    }

    console.log(solutionArray.join(""))

}

/**
 *
Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n.
The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:

She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .
Let ui be the cost of the i-th cheapest stone (the cost that will be on the i-th place if we arrange all the stone costs in non-decreasing order).
This time she will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .
For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.

Input
The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n integers: v1, v2, ..., vn (1 ≤ vi ≤ 109) — costs of the stones.

The third line contains an integer m (1 ≤ m ≤ 105) — the number of Kuriyama Mirai's questions. Then follow m lines, each line contains three integers type,
 l and r (1 ≤ l ≤ r ≤ n; 1 ≤ type ≤ 2), describing a question. If type equal to 1, then you should output the answer for the first question,
 else you should output the answer for the second one.

Output
Print m lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.

[ 6, 10, 12, 19, 21, 28 ]

[ 2, 4, 8, 14, 21, 28 ]

Examples
input
6
6 4 2 7 2 7
3
2 3 6
1 3 4
1 1 6
output
24
9
28
input
4
5 5 2 3
10
1 2 4
2 1 4
1 1 1
2 1 4
2 1 2
1 1 1
1 3 3
1 1 3
1 4 4
1 2 2
output
10
15
5
15
5
5
2
12
3
5
 */

let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    let lenthOfInput = Number(inputString[0])
    let input = inputString[1].split(" ");
    let lengthOfQuestion = Number(inputString[2])
    let questions = inputString.slice(3)

    solution(lenthOfInput, input, lengthOfQuestion, questions);

});

function solution(lenthOfInput, input, lengthOfQuestion, questions) {

    let perfixSum = [];
    let sortedPerfixSum = [];
    let solutionArray = [];

    for (let index = 0; index < lenthOfInput; index++) {

        perfixSum[index] = (perfixSum[index - 1] ? perfixSum[index - 1] : 0) + Number(input[index])
    }

    input.sort(function (current, next) {
        return current - next;
    })

    for (let index = 0; index < lenthOfInput; index++) {

        sortedPerfixSum[index] = (sortedPerfixSum[index - 1] ? sortedPerfixSum[index - 1] : 0) + Number(input[index])
    }

    for (let index = 0; index < lengthOfQuestion; index++) {

        let question = Number(questions[index].split(" ")[0]);
        let left = Number(questions[index].split(" ")[1])
        let right = Number(questions[index].split(" ")[2])
        let solution;

        if (question == 1)

            solution = perfixSum[right - 1] - (perfixSum[left - 2] ? perfixSum[left - 2] : 0)
        else
            solution = sortedPerfixSum[right - 1] - (sortedPerfixSum[left - 2] ? sortedPerfixSum[left - 2] : 0)

        solutionArray.push(solution);
        solutionArray.push("\n")

    }

    console.log(solutionArray.join(""));

}

var lenArr = readline().split(' ').map(Number); //к-сть каменів
var ArrNormal = readline().split(' ').map(Number); //масив з цінами каменів
var numQue = readline().split(' ').map(Number); //к-сть запитань
var queArr = []; //пустий масив для запитань
var ArrSort = ArrNormal.slice().sort(); //відсортований масив
for (var i=0; i<numQue; i++) { //цикл по к-сті запитань
    var summ = 0;
    queArr[i] = readline().split(' ').map(Number); //зчитування і-го запитання
    if (queArr[i][0] == 1) { // якщо умова 1
        for (var j=queArr[i][1]-1; j<queArr[i][2]; j++) { //цикл від l до r
            summ += ArrNormal[j]; //сума віх цін від l до r
        }
    }
    else { //якщо умова 2
        for (var k=queArr[i][1]-1; k<queArr[i][2]; k++) { //цикл від l до r
            summ += ArrSort[k]; //сума віх цін від l до r
        }
    }
    print(summ); //результат
}

const lines = [];

const helpers = {
  arrStringtoInt: (arr, splitter) => {
    return arr.split(splitter).map(num => parseInt(num));
  },
  insterAt: (arr, idx, item) => {
    const newArray = [...arr];
    newArray.splice(idx, 0, item);
    return newArray;
  },
  sortAscending: (arr) => {
    return arr.sort((a, b) => a - b);
  },
  sortDescending(arr) {
    return arr.sort((a, b) => b - a);
  }
}

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

// multi line input
readline.on('line', line => {
  lines.push(line);
});

readline.on('close', line => {
  const numbers = helpers.arrStringtoInt(lines[1], ' ');
  const rangeSum1 = [0];
  const rangeSum2 = [0];

  for (let ii = 0; ii < numbers.length; ii++) {
    rangeSum1.push(numbers[ii] + rangeSum1[ii]);
  }

  numbers.sort((a, b) => b - a);

  for (let ii = 0; ii < numbers.length; ii++) {
    rangeSum2.push(numbers[ii] + rangeSum2[ii]);
  }

  // // Calculate the range sum
  for (let ii = 3; ii < lines.length; ii++) {
    const inputs = helpers.arrStringtoInt(lines[ii], ' ');
    const t = inputs[0];
    const l = inputs[1];
    const r = inputs[2];
    if (t == 1)
      console.log(answer(rangeSum1, l, r))
    else
      console.log( rangeSum2[r-l+1])
  }

});

function answer(arr, l, r) {
  return arr[r] - arr[l - 1];
}


/**
 * 04/19/21 morning
 * https://codeforces.com/contest/1514/problem/A
 */

///////////////////////////////// pre-define /////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
///////////////////////////////////////////////////////////////////////////////////

const solve = (n, a) => {
    // pr(n,a);
    for (const e of a) {
        let q = sq(e);
        if (q != q >> 0) return pr('YES');
    }
    pr('NO')
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i + 1]);
            i += 2;
        }
    });
};

main()

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
data += chunk;
});

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {

        const n = parseInt(readLine());

        const a = readLine().split(' ').map(Number);

        let end = true;
        for(let i = 0; i < n; i++){
            if(!Number.isInteger(Math.sqrt(a[i]))){
                console.log('YES');
                end = false;
                break;
            }
        }
        if(end) console.log('NO')
    }
});

function readLine() {
        return data[currentLine++];
}

function A(a){
    return Number.isInteger(Math.sqrt(a.reduce((a,b) => a*b)));
}

module.exports = A;

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j];
        }else{
            var k = lines[j].split(' ').map(Number);
            var found = false;
            for(var l = 0; l < k.length; l++){
                var a = Math.floor(Math.sqrt(k[l]));
                if(a * a != k[l]){
                    found = true;
                    break;
                }
            }
            if(found === true){
                console.log('YES');
            }else{
                console.log('NO');
            }
        }
    }
});

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
let input = [];
rl.on('line', line => {
    input.push(line);
})
rl.on('close', line => {
    var t = Number(input[0]);
    var j = 1;
    for (var a = 0; a < t; a++) {
        var n = input[j];
        j++;
        var arr = input[j].split(" ").map((i) => {
            return Number(i);
        });
        j++;
        function isSquareNumber(num) {
            var root = Math.sqrt(num)
            return root === Math.floor(root);
        }
        var i;

        for (i = 0; i < arr.length; i++) {
            if (!isSquareNumber(arr[i])) {
                break;
            }
        }
        if (i === arr.length) {
            console.log("NO");
        } else {
            console.log("YES");
        }
    }
})

let input = '';
process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	const lines = input.trim().split('\n').slice(1);

	for (let i=1; i<lines.length; i+=2) {
		const arr = lines[i].split(' ');

		let flag = true;
		for (let j=0; j<arr.length; j++) {
			if (Math.sqrt(+arr[j])%1 !== 0) {
				flag = false;
				break;
			}
		}

		console.log(!flag ? 'YES' : 'NO');
	}
})

"use strict";
//////////// LIBS
Object.defineProperty(exports, "__esModule", { value: true });
class IO {
    constructor() {
        this.lines = [];
        this.tokens = [];
        this.lines = require('fs').readFileSync(0, 'utf8').split('\n');
    }
    getTokens() {
        if (!this.tokens.length) {
            this.tokens = this.nextLine().split(' ');
        }
        return this.tokens;
    }
    nextLine() {
        return this.lines.shift().trim();
    }
    nextNum() {
        return Number(this.getTokens().shift());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
}
function solve(n, tab) {
    for (let a of tab) {
        if (Math.floor(Math.sqrt(a)) ** 2 !== a) {
            console.log('YES');
            return;
        }
    }
    console.log('NO');
}
function main() {
    const io = new IO();
    let t = io.nextNum();
    while (t--) {
        let n = io.nextNum();
        let tab = io.nextNumArray(n);
        solve(n, tab);
    }
}
main();

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------

function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		var isOK = false;
		for(var j = 0; j < N; j++){
			if(list[j] == 1){
				continue;
			}
			var map = getPrimeFactorization(list[j]);
			var keys = Object.keys(map);
			for(var k = 0; k < keys.length; k++){
				if(map[keys[k]] % 2 == 1){
					isOK = true;
				}
			}
		}
		myout((isOK) ? "YES" : "NO");
	}
}
function getPrimeFactorization(val){
  var primeMap = {};
  var div = 2;
  if(isPrime(val)){
    primeMap[val] = 1;
    return primeMap;
  }
  while(val != 1){
    if(val % div == 0){
      var count = 2;
      while(val % Math.pow(div, count) == 0){
         count++;
      }
      (primeMap[div] == null)  ? primeMap[div] = (count - 1) : primeMap[div] += (count - 1);
      val /= Math.pow(div, count - 1);
      if(isPrime(val)){
        (primeMap[val] == null)  ? primeMap[val] = 1 : primeMap[val]++;
        break;
      }
    }
    div = (div == 2) ? div + 1 : div + 2;
  }
  return primeMap;
}
function isPrime(val){
  if(val == null || val <= 1 || (val != 2 && val % 2 == 0)){
    return false;
  }else if(val == 2){
    return true;
  }
  var root = Math.floor(Math.sqrt(val));
  for(var i = 3; i <= root; i += 2){
    if(val % i == 0){
      return false;
    }
  }
  return true;
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    var n = parseInt(readline());
    // var [a, b] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    for (let j = 0; j < n; j++) {
      var res = Math.floor(Math.sqrt(a[j]))
      if(res *res !==a[j]) return console.log('YES')
    }
    console.log('NO')
    // var aa = a.slice()
    // a.sort((a, b) => a - b)
    //
    // dp = new Array(n + 1)
    // for (let i = 0; i < n + 1; i++) {
    //   dp[i] = new Array(n).fill(Number.MAX_SAFE_INTEGER)
    // }

  })
}

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
data += chunk;
});

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {

        const n = parseInt(readLine());

        const a = readLine().split(' ').map(Number);

        for(let i = 0; i < n; i++){
            if(!Number.isInteger(Math.sqrt(a[i]))){
                console.log('YES');
            }
        }
        console.log('NO')
    }
});

function readLine() {
        return data[currentLine++];
}

function A(a){
    return Number.isInteger(Math.sqrt(a.reduce((a,b) => a*b)));
}

module.exports = A;

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
data += chunk;
});

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {

        const n = parseInt(readLine());

        const a = readLine().split(' ').map(Number);

        A(a) ? console.log('NO'): console.log('YES');
    }
});

function readLine() {
        return data[currentLine++];
}

function A(a){
    return Number.isInteger(Math.sqrt(a.reduce((a,b) => a*b)));
}

module.exports = A;

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j];
        }else{
            var k = lines[j].split(' ').map(Number);
            var total = k[0];
            for(var l = 1; l < k.length; l++){
                total *= k[l];
            }
            total = Math.sqrt(total);
            if(total % 1 !== 0){
                console.log('YES');
            }else{
                console.log('NO');
            }
        }
    }
});

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
let input = [];
rl.on('line', line => {
    input.push(line);
})
rl.on('close', line => {
    var t = Number(input[0]);
    var j = 1;
    for (var a = 0; a < t; a++) {
        var n = input[j];
        j++;
        var arr = input[j].split(" ").map((i) => {
            return Number(i);
        });
        j++;
        function isSquareNumber(num) {
            return Math.sqrt(num) ** 2 === num;
        }
        var i;
        for (i = 0; i < arr.length; i++) {
            if (!isSquareNumber(arr[i])) {
                break;
            }
        }
        if (i === arr.length) {
            console.log("NO");
        } else {
            console.log("YES");
        }
    }
})

let input = '';
process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	const lines = input.trim().split('\n').slice(1);

	for (let i=1; i<lines.length; i+=2) {
		const arr = lines[i].split(' ');

		let flag = true;
		for (let j=0; j<arr.length; j++) {
			if (Math.sqrt(+arr[j])%1 !== 0) {
				flag = false;
				break;
			}
		}

		console.log(flag ? 'YES' : 'NO');
	}
})


var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)
var write = this.write || require('lol-io').write; //write --> creates output.txt with output
var readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt

var n, a, b, ans = false;

function isPrime(num) {
    for (var i = 2; i < num; i++)
        if(num % i === 0) return false;
    return num > 1;
}

n = Number(readline());
a = n + 2;
b = 2;

while (!ans) {

    if (!isPrime(a) && !isPrime(b)) {

        ans = true;
        break
    } else {

        a++;
        b++;
    }
}

print(`${a} ${b}`)

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

readline.on('line', line => {
  let num = Number(line);
  if (num === 1) return console.log(`9 8`);
  console.log(`${(num * 2) + num} ${num * 2}`);
});

// readline.on("close", () => {
//   console.log(count, values);
// });

function myout(t){print(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main() {
  var N = myconv(readline(),1);
  var a = N + 1;
  while(isPrime(a)){
      a++;
  }
  var b = a + N;
  while(isPrime(a) || isPrime(b)){
      a++;
      b++;
  }
  myout(b + " " + a);
}
function isPrime(val){
        if(val <= 1 || (val != 2 && val % 2 == 0)){
                return false;
        }else if(val == 2){
                return true;
        }
        var root = Math.floor(Math.sqrt(val));
        for(var i = 3; i <= root; i += 2){
                if(val % i == 0){
                        return false;
                }
        }
        return true;
}
Main();

let fs = require('fs');

let txt = fs.readFileSync(0, "utf-8").split("\n").filter(data => data.length > 0);
for (let i = 0; i < txt.length; i ++) {
    doit(txt[i] * 1);
}

function doit(num) {
    let max=num*2,min=num;
    while (true) {
        if(check(max) &&check(min)){
            console.log(max,min);
            break;
        }else{
            ++max;
            ++min;
        }
    }
}
function check(num){
    for (let i = 2; i < num/2; i++) {
        if(num%i===0)return true;

    }
    return false;
}

var T = parseInt(readline());
print(T * 9 + ' ' + T * 8);

var a = parseInt(readline());

var c = (a + 2) * 3;
var b = c - a;

print(c, b);

process.stdin.resume()
process.stdin.setEncoding('utf-8')

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))

  const n = parseInt(arr[0])
  let a, b
  if(n % 2 == 1) {
    a = n + 9
    b = 9
  }
  else {
    a = n + 4
    b = 4
  }
  wr(a, b)
})

function wr(...x) {
  console.log(...x)
}

function max(...x) {
  return Math.max(...x)
}

function min(...x) {
  return Math.min(...x)
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', (d) => {
  const n = +d;

  if (n % 2 === 0) {
    console.log(n + 10, 10);
  }
  else {
    console.log(n + 9, 9);
  }
});

function myout(t){print(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main() {
  var N = myconv(readline(),1);
  var a = N + 1;
  if(isPrime(a)){
      a++;
  }
  var b = a + N;
  while(isPrime(b)){
      b++;
  }
  myout(b + " " + a);
}
function isPrime(val){
        if(val <= 1 || (val != 2 && val % 2 == 0)){
                return false;
        }else if(val == 2){
                return true;
        }
        var root = Math.floor(Math.sqrt(val));
        for(var i = 3; i <= root; i += 2){
                if(val % i == 0){
                        return false;
                }
        }
        return true;
}
Main();

function myout(t){print(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main() {
  var N = myconv(readline(),1);
  var a = N + 1;
  while(isPrime(a)){
      a++;
  }
  var b = a + N;
  while(isPrime(b)){
      a++;
      b++;
  }
  myout(b + " " + a);
}
function isPrime(val){
        if(val <= 1 || (val != 2 && val % 2 == 0)){
                return false;
        }else if(val == 2){
                return true;
        }
        var root = Math.floor(Math.sqrt(val));
        for(var i = 3; i <= root; i += 2){
                if(val % i == 0){
                        return false;
                }
        }
        return true;
}
Main();

function myout(t){print(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main() {
  var N = myconv(readline(),1);
  var a = N + 1;
  if(isPrime(a)){
      a++;
  }
  var b = a + N;
  while(isPrime(b)){
      b++;
  }
  myout(a + " " + b);
}
function isPrime(val){
        if(val <= 1 || (val != 2 && val % 2 == 0)){
                return false;
        }else if(val == 2){
                return true;
        }
        var root = Math.floor(Math.sqrt(val));
        for(var i = 3; i <= root; i += 2){
                if(val % i == 0){
                        return false;
                }
        }
        return true;
}
Main();

var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)
var write = this.write || require('lol-io').write; //write --> creates output.txt with output
var readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt

var n, a, b, ans = false;

function isPrime(num) {
    for (var i = 2; i < num; i++)
        if(num % i === 0) return false;
    return num > 1;
}

n = Number(readline());
a = n + 1;
b = 1;

while (!ans) {

    if (!isPrime(a) && !isPrime(b)) {

        ans = true;
        break
    } else {

        a++;
        b++;
    }
}

print(`${a} ${b}`)

var k = parseInt(readline());
print(k*5 +' '+ k*4);

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

readline.on('line', line => {
  let num = Number(line);
  if (num === 1) return console.log(`8 9`);
  console.log(`${num * 2} ${(num * 2) + num}`);
});

// readline.on("close", () => {
//   console.log(count, values);
// });

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

readline.on('line', line => {
  let num = Number(line);
  if (num === 1) console.log(`8 9`);
  console.log(`${num * 2} ${(num * 2) + num}`);
});

// readline.on("close", () => {
//   console.log(count, values);
// });


"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function sieve(max) {
    let arr = [];
    for (let i = 2; i <= max; i++) {
        arr[i] = 1;
    }
    for (let i = 2; i <= max; i++) {
        if (arr[i]) {
            for (let j = 2 * i; j <= max; j += i) {
                arr[j] = 0;
            }
        }
    }
    let ret = [];
    for (let i = 2; i <= max; i++) {
        if (arr[i]) {
            ret.push(i);
        }
    }
    return ret;
}
function getPrimeFactors(val, primes) {
    let ret = [];
    for (let j = 0; j < primes.length && val >= primes[j]; j++) {
        let p = primes[j];
        if (val % p == 0) {
            ret.push(p);
        }
    }
    return ret;
}
function hasSortedIntersection(tab1, tab2) {
    let i = 0;
    let j = 0;
    while (i < tab1.length && j < tab2.length) {
        let v1 = tab1[i];
        let v2 = tab2[j];
        if (v1 === v2) {
            return true;
        }
        if (v1 < v2) {
            i++;
        }
        else {
            j++;
        }
    }
    return false;
}
function mergeSorted(tab1, tab2) {
    let i = 0;
    let j = 0;
    let ret = [];
    while (i < tab1.length && j < tab2.length) {
        let v1 = tab1[i];
        let v2 = tab2[j];
        if (v1 < v2) {
            ret.push(v1);
            i++;
        }
        else {
            ret.push(v2);
            j++;
        }
    }
    ret.push(...tab1.slice(i), ...tab2.slice(j));
    return ret;
}
function getDividers(max) {
    const ret = [];
    for (let i = 1; i <= max; i++) {
        ret[i] = [];
    }
    for (let i = 2; i <= max; i++) {
        if (!ret[i].length) {
            for (let j = i; j <= max; j += i) {
                ret[j].push(i);
            }
        }
    }
    return ret;
}
function solve(tab, queries) {
    let dividers = getDividers(100000);
    let n = tab.length;
    let up = Array.from({ length: n + 1 }).map(() => []);
    let next = [];
    up[n][0] = n;
    for (let i = n - 1; i >= 0; i--) {
        let val = tab[i];
        let factors = dividers[val];
        let nextIndex = n;
        for (let factor of factors) {
            if (next[factor]) {
                nextIndex = Math.min(nextIndex, next[factor]);
            }
            next[factor] = i;
        }
        up[i][0] = Math.min(nextIndex, up[i + 1][0]);
    }
    for (let k = 1; k < 20; k++) {
        for (let i = 0; i <= n; i++) {
            let parent = up[i][k - 1];
            up[i][k] = up[parent][k - 1];
        }
    }
    queries.forEach(([l, r]) => {
        l--;
        r--;
        let ret = 1;
        for (let k = 19; k >= 0; k--) {
            if (up[l][k] <= r) {
                l = up[l][k];
                ret += 1 << k;
            }
        }
        io.writeLine(ret);
    });
}
function main() {
    try {
        let n = io.nextNum();
        let q = io.nextNum();
        let tab = io.nextNumArray(n);
        let queries = [];
        while (q--) {
            queries.push([io.nextNum(), io.nextNum()]);
        }
        solve(tab, queries);
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function sieve(max) {
    let arr = [];
    for (let i = 2; i <= max; i++) {
        arr[i] = 1;
    }
    for (let i = 2; i <= max; i++) {
        if (arr[i]) {
            for (let j = 2 * i; j <= max; j += i) {
                arr[j] = 0;
            }
        }
    }
    let ret = [];
    for (let i = 2; i <= max; i++) {
        if (arr[i]) {
            ret.push(i);
        }
    }
    return ret;
}
function getPrimeFactors(val, primes) {
    let ret = [];
    for (let j = 0; j < primes.length && val >= primes[j]; j++) {
        let p = primes[j];
        if (val % p == 0) {
            ret.push(p);
        }
    }
    return ret;
}
function hasSortedIntersection(tab1, tab2) {
    let i = 0;
    let j = 0;
    while (i < tab1.length && j < tab2.length) {
        let v1 = tab1[i];
        let v2 = tab2[j];
        if (v1 === v2) {
            return true;
        }
        if (v1 < v2) {
            i++;
        }
        else {
            j++;
        }
    }
    return false;
}
function mergeSorted(tab1, tab2) {
    let i = 0;
    let j = 0;
    let ret = [];
    while (i < tab1.length && j < tab2.length) {
        let v1 = tab1[i];
        let v2 = tab2[j];
        if (v1 < v2) {
            ret.push(v1);
            i++;
        }
        else {
            ret.push(v2);
            j++;
        }
    }
    ret.push(...tab1.slice(i), ...tab2.slice(j));
    return ret;
}
function getDividers(max) {
    const ret = [];
    for (let i = 1; i <= max; i++) {
        ret[i] = [];
    }
    for (let i = 2; i <= max; i++) {
        if (!ret[i].length) {
            for (let j = i; j <= max; j += i) {
                ret[j].push(i);
            }
        }
    }
    return ret;
}
function solve(tab, queries) {
    // let primes = sieve(100000);
    let dividers = getDividers(100000);
    let n = tab.length;
    let up = Array.from({ length: n + 1 }).map(() => []);
    let next = [];
    // console.log(getDividers(40).map((x, i) => [i, x]));
    up[n][0] = n;
    for (let i = n - 1; i >= 0; i--) {
        let val = tab[i];
        // const factors = getPrimeFactors(val, primes);
        let factors = dividers[val];
        let nextIndex = n;
        factors.forEach((factor) => {
            if (next[factor]) {
                nextIndex = Math.min(nextIndex, next[factor]);
            }
            next[factor] = i;
        });
        up[i][0] = Math.min(nextIndex, up[i + 1][0]);
    }
    for (let k = 1; k < 20; k++) {
        for (let i = 0; i <= n; i++) {
            let parent = up[i][k - 1];
            up[i][k] = up[parent][k - 1];
        }
    }
    queries.forEach(([l, r]) => {
        l--;
        r--;
        let ret = 1;
        for (let k = 19; k >= 0; k--) {
            if (up[l][k] <= r) {
                l = up[l][k];
                ret += 1 << k;
            }
        }
        io.writeLine(ret);
    });
}
function main() {
    try {
        let n = io.nextNum();
        let q = io.nextNum();
        let tab = io.nextNumArray(n);
        let queries = [];
        while (q--) {
            queries.push([io.nextNum(), io.nextNum()]);
        }
        solve(tab, queries);
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function sieve(max) {
    let arr = [];
    for (let i = 2; i <= max; i++) {
        arr[i] = 1;
    }
    for (let i = 2; i <= max; i++) {
        if (arr[i]) {
            for (let j = 2 * i; j <= max; j += i) {
                arr[j] = 0;
            }
        }
    }
    let ret = [];
    for (let i = 2; i <= max; i++) {
        if (arr[i]) {
            ret.push(i);
        }
    }
    return ret;
}
function getPrimeFactors(val, primes) {
    let ret = [];
    for (let j = 0; j < primes.length && val >= primes[j]; j++) {
        let p = primes[j];
        if (val % p == 0) {
            ret.push(p);
        }
    }
    return ret;
}
function hasSortedIntersection(tab1, tab2) {
    let i = 0;
    let j = 0;
    while (i < tab1.length && j < tab2.length) {
        let v1 = tab1[i];
        let v2 = tab2[j];
        if (v1 === v2) {
            return true;
        }
        if (v1 < v2) {
            i++;
        }
        else {
            j++;
        }
    }
    return false;
}
function mergeSorted(tab1, tab2) {
    let i = 0;
    let j = 0;
    let ret = [];
    while (i < tab1.length && j < tab2.length) {
        let v1 = tab1[i];
        let v2 = tab2[j];
        if (v1 < v2) {
            ret.push(v1);
            i++;
        }
        else {
            ret.push(v2);
            j++;
        }
    }
    ret.push(...tab1.slice(i), ...tab2.slice(j));
    return ret;
}
function getDividers(max) {
    const ret = [];
    for (let i = 2; i <= max; i++) {
        ret[i] = [];
    }
    for (let i = 2; i <= max; i++) {
        if (!ret[i].length) {
            for (let j = i; j <= max; j += i) {
                ret[j].push(i);
            }
        }
    }
    return ret;
}
function solve(tab, queries) {
    // let primes = sieve(100000);
    let dividers = getDividers(100000 + 2);
    let n = tab.length;
    let up = Array.from({ length: n + 1 }).map(() => []);
    let next = [];
    // console.log(getDividers(40).map((x, i) => [i, x]));
    up[n][0] = n;
    for (let i = n - 1; i >= 0; i--) {
        let val = tab[i];
        // const factors = getPrimeFactors(val, primes);
        let factors = dividers[val];
        let nextIndex = n;
        factors.forEach((factor) => {
            if (next[factor]) {
                nextIndex = Math.min(nextIndex, next[factor]);
            }
            next[factor] = i;
        });
        up[i][0] = Math.min(nextIndex, up[i + 1][0]);
    }
    for (let k = 1; k < 20; k++) {
        for (let i = 0; i <= n; i++) {
            let parent = up[i][k - 1];
            up[i][k] = up[parent][k - 1];
        }
    }
    queries.forEach(([l, r]) => {
        l--;
        r--;
        let ret = 1;
        for (let k = 19; k >= 0; k--) {
            if (up[l][k] <= r) {
                l = up[l][k];
                ret += 1 << k;
            }
        }
        io.writeLine(ret);
    });
}
function main() {
    try {
        let n = io.nextNum();
        let q = io.nextNum();
        let tab = io.nextNumArray(n);
        let queries = [];
        while (q--) {
            queries.push([io.nextNum(), io.nextNum()]);
        }
        solve(tab, queries);
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function sieve(max) {
    let arr = [];
    for (let i = 2; i <= max; i++) {
        arr[i] = 1;
    }
    for (let i = 2; i <= max; i++) {
        if (arr[i]) {
            for (let j = 2 * i; j <= max; j += i) {
                arr[j] = 0;
            }
        }
    }
    let ret = [];
    for (let i = 2; i <= max; i++) {
        if (arr[i]) {
            ret.push(i);
        }
    }
    return ret;
}
function getPrimeFactors(val, primes) {
    let ret = [];
    for (let j = 0; j < primes.length && val >= primes[j]; j++) {
        let p = primes[j];
        if (val % p == 0) {
            ret.push(p);
        }
    }
    return ret;
}
function hasSortedIntersection(tab1, tab2) {
    let i = 0;
    let j = 0;
    while (i < tab1.length && j < tab2.length) {
        let v1 = tab1[i];
        let v2 = tab2[j];
        if (v1 === v2) {
            return true;
        }
        if (v1 < v2) {
            i++;
        }
        else {
            j++;
        }
    }
    return false;
}
function mergeSorted(tab1, tab2) {
    let i = 0;
    let j = 0;
    let ret = [];
    while (i < tab1.length && j < tab2.length) {
        let v1 = tab1[i];
        let v2 = tab2[j];
        if (v1 < v2) {
            ret.push(v1);
            i++;
        }
        else {
            ret.push(v2);
            j++;
        }
    }
    ret.push(...tab1.slice(i), ...tab2.slice(j));
    return ret;
}
function getDividers(max) {
    const ret = [];
    for (let i = 2; i <= max; i++) {
        ret[i] = [];
    }
    for (let i = 2; i <= max; i++) {
        if (!ret[i].length) {
            for (let j = i; j <= max; j += i) {
                ret[j].push(i);
            }
        }
    }
    return ret;
}
function solve(tab, queries) {
    // let primes = sieve(100000);
    let dividers = getDividers(100000);
    let n = tab.length;
    let up = Array.from({ length: n + 1 }).map(() => []);
    let next = [];
    // console.log(getDividers(40).map((x, i) => [i, x]));
    up[n][0] = n;
    for (let i = n - 1; i >= 0; i--) {
        let val = tab[i];
        // const factors = getPrimeFactors(val, primes);
        let factors = dividers[val];
        let nextIndex = n;
        factors.forEach((factor) => {
            if (next[factor]) {
                nextIndex = Math.min(nextIndex, next[factor]);
            }
            next[factor] = i;
        });
        up[i][0] = Math.min(nextIndex, up[i + 1][0]);
    }
    for (let k = 1; k < 20; k++) {
        for (let i = 0; i <= n; i++) {
            let parent = up[i][k - 1];
            up[i][k] = up[parent][k - 1];
        }
    }
    queries.forEach(([l, r]) => {
        l--;
        r--;
        let ret = 1;
        for (let k = 19; k >= 0; k--) {
            if (up[l][k] <= r) {
                l = up[l][k];
                ret += 1 << k;
            }
        }
        io.writeLine(ret);
    });
}
function main() {
    try {
        let n = io.nextNum();
        let q = io.nextNum();
        let tab = io.nextNumArray(n);
        let queries = [];
        while (q--) {
            queries.push([io.nextNum(), io.nextNum()]);
        }
        solve(tab, queries);
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function sieve(max) {
    let arr = [];
    for (let i = 2; i <= max; i++) {
        arr[i] = 1;
    }
    for (let i = 2; i <= max; i++) {
        if (arr[i]) {
            for (let j = 2 * i; j <= max; j += i) {
                arr[j] = 0;
            }
        }
    }
    let ret = [];
    for (let i = 2; i <= max; i++) {
        if (arr[i]) {
            ret.push(i);
        }
    }
    return ret;
}
function getPrimeFactors(val, primes) {
    let ret = [];
    for (let j = 0; j < primes.length && val >= primes[j]; j++) {
        let p = primes[j];
        if (val % p == 0) {
            ret.push(p);
        }
    }
    return ret;
}
function hasSortedIntersection(tab1, tab2) {
    let i = 0;
    let j = 0;
    while (i < tab1.length && j < tab2.length) {
        let v1 = tab1[i];
        let v2 = tab2[j];
        if (v1 === v2) {
            return true;
        }
        if (v1 < v2) {
            i++;
        }
        else {
            j++;
        }
    }
    return false;
}
function mergeSorted(tab1, tab2) {
    let i = 0;
    let j = 0;
    let ret = [];
    while (i < tab1.length && j < tab2.length) {
        let v1 = tab1[i];
        let v2 = tab2[j];
        if (v1 < v2) {
            ret.push(v1);
            i++;
        }
        else {
            ret.push(v2);
            j++;
        }
    }
    ret.push(...tab1.slice(i), ...tab2.slice(j));
    return ret;
}
function solve(tab, queries) {
    let primes = sieve(10000);
    let n = tab.length;
    let up = Array.from({ length: n + 1 }).map(() => []);
    let next = [];
    up[n][0] = n;
    for (let i = n - 1; i >= 0; i--) {
        let val = tab[i];
        const factors = getPrimeFactors(val, primes);
        let nextIndex = n;
        factors.forEach((factor) => {
            if (next[factor]) {
                nextIndex = Math.min(nextIndex, next[factor]);
            }
            next[factor] = i;
        });
        up[i][0] = Math.min(nextIndex, up[i + 1][0]);
    }
    for (let k = 1; k < 20; k++) {
        for (let i = 0; i <= n; i++) {
            let parent = up[i][k - 1];
            up[i][k] = up[parent][k - 1];
        }
    }
    queries.forEach(([l, r]) => {
        l--;
        r--;
        let ret = 1;
        for (let k = 19; k >= 0; k--) {
            if (up[l][k] <= r) {
                l = up[l][k];
                ret += 1 << k;
            }
        }
        io.writeLine(ret);
    });
}
function main() {
    try {
        let n = io.nextNum();
        let q = io.nextNum();
        let tab = io.nextNumArray(n);
        let queries = [];
        while (q--) {
            queries.push([io.nextNum(), io.nextNum()]);
        }
        solve(tab, queries);
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function sieve(max) {
    let arr = [];
    for (let i = 2; i <= max; i++) {
        arr[i] = 1;
    }
    for (let i = 2; i <= max; i++) {
        if (arr[i]) {
            for (let j = 2 * i; j <= max; j += i) {
                arr[j] = 0;
            }
        }
    }
    let ret = [];
    for (let i = 2; i <= max; i++) {
        if (arr[i]) {
            ret.push(i);
        }
    }
    return ret;
}
function getPrimeFactors(val, primes) {
    let ret = [];
    for (let j = 0; j < primes.length && val >= primes[j]; j++) {
        let p = primes[j];
        if (val % p == 0) {
            ret.push(p);
        }
    }
    return ret;
}
function hasSortedIntersection(tab1, tab2) {
    let i = 0;
    let j = 0;
    while (i < tab1.length && j < tab2.length) {
        let v1 = tab1[i];
        let v2 = tab2[j];
        if (v1 === v2) {
            return true;
        }
        if (v1 < v2) {
            i++;
        }
        else {
            j++;
        }
    }
    return false;
}
// console.log(hasSortedIntersection([1, 4, 5, 9], [1, 2, 2]));
function mergeSorted(tab1, tab2) {
    let i = 0;
    let j = 0;
    let ret = [];
    while (i < tab1.length && j < tab2.length) {
        let v1 = tab1[i];
        let v2 = tab2[j];
        if (v1 < v2) {
            ret.push(v1);
            i++;
        }
        else {
            ret.push(v2);
            j++;
        }
    }
    ret.push(...tab1.slice(i), ...tab2.slice(j));
    return ret;
}
function solve(tab, queries) {
    let primes = sieve(10000);
    // console.log(primes);
    let n = tab.length;
    let up = Array.from({ length: n + 1 }).map(() => []);
    let next = [];
    up[n][0] = n;
    for (let i = n - 1; i >= 0; i--) {
        let val = tab[i];
        const factors = getPrimeFactors(val, primes);
        let nextIndex = n;
        factors.forEach((factor) => {
            if (next[factor]) {
                nextIndex = Math.min(nextIndex, next[factor]);
            }
            next[factor] = i;
        });
        up[i][0] = Math.min(nextIndex, up[i + 1][0]);
        // console.log({ i, nextIndex, ranges: up, next, factors });
    }
    for (let k = 1; k < 20; k++) {
        for (let i = 0; i <= n; i++) {
            let parent = up[i][k - 1];
            // console.log({ i, k, parent });
            up[i][k] = up[parent][k - 1];
        }
        let ret = [];
        for (let i = 0; i <= n; i++) {
            ret.push(up[i][k]);
        }
        // console.log({ k, ret });
        // console.log(up);
    }
    queries.forEach(([l, r]) => {
        l--;
        r--;
        let ret = 1;
        for (let k = 20; k >= 0; k--) {
            if (up[l][k] <= r) {
                l = up[l][k];
                ret += 1 << k;
            }
        }
        io.writeLine(ret);
    });
    // console.log(up);
    // let prevFactors: number[] = [];
    // let currentFactors: number[] = [];
    // let n = tab.length;
    // ranges[n] = n + 1;
    // for (let i = n - 1; i >= 0; i--) {
    //   let val = tab[i];
    //   const factors = getPrimeFactors(val, primes);
    // }
    // for (let i = 0; i < tab.length; i++) {
    //   let val = tab[i];
    //   const factors = getPrimeFactors(val, primes);
    //   // console.log({ i, val, factors, prevFactors });
    //   if (prevFactors.length && !hasSortedIntersection(prevFactors, factors)) {
    //     // console.log('----');
    //     ranges.push(i + 1);
    //   }
    //   prevFactors = mergeSorted(prevFactors, factors);
    // }
    // console.log(ranges);
    // for (let [l, r] of queries) {
    //   l--;
    //   r--;
    //   let lower = upperBound(ranges, l);
    //   console.log('----');
    //   console.log({
    //     lower_l: lowerBound(ranges, l),
    //     upper_l: upperBound(ranges, l),
    //     lower_r: lowerBound(ranges, r),
    //     upper_r: upperBound(ranges, r),
    //   });
    //   let upper = upperBound(ranges, r);
    //   console.log({ l, r, lower, upper });
    //   io.writeLine(upper - lower + 1);
    // }
    // console.log(ranges);
}
function main() {
    try {
        let n = io.nextNum();
        let q = io.nextNum();
        let tab = io.nextNumArray(n);
        let queries = [];
        while (q--) {
            queries.push([io.nextNum(), io.nextNum()]);
        }
        solve(tab, queries);
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();


(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    }

    var x = read.number();
    var x2b = x.toString(2);
    var res = [];
    var t = 0;
    while(x2b.indexOf(0) !== -1) {
        if(t%2==0) {
            x2b = x2b.replace(/^0+/, '');
            x2b = ((+('0b' +x2b))^((Math.pow(2, x2b.length))-1)).toString(2);
            res.push(x2b.length);
        }
        else {
            x2b = (+('0b' + x2b) + 1).toString(2)
        }
        t++;
    }

    print(t);
    if(res.length)
        print(res.join(' '));
}());

var x = parseInt(readline())
var q = [{ x:x, s:0}];

var vis = {}, lastx = x, res=[], count = 0;
while( q.length > 0) {

    var cur = q.shift();

    if ( cur.s > 40) continue;
    count = cur.s;
    var t = (cur.x+1);
    var check = t.toString(2).split('').filter(d=>(d==='1')).length === 1;
    if (check) break;

    lastx = cur.x;
    if (cur.s%2 === 0) {
        var a = cur.x.toString(2);
        n = a.length - a.indexOf('0')
        res.push(n)
        q.push({
            x: cur.x ^ (Math.pow(2, n) - 1),
            s: (cur.s+1)
        });
    } else {
        q.push({
            x: cur.x+1,
            s: (cur.s+1)
        });
    }

}

print(count)
print(res.join(' '))

var x = parseInt(readline())

var q = [{ x, s:0}];

var vis = {}, lastx = x, res=[];
while( q.length > 0) {

    var cur = q.shift();

    if ( vis[cur.x] || cur.s > 40) continue;
    vis[cur.x] = true;

    var check = (cur.x+1).toString(2).split('').filter(d=>(d==='1')).length === 1;
    if (check) break;

    lastx = cur.x;
    if (cur.s%2 === 0) {
        var a = cur.x.toString(2);
        n = a.length - a.indexOf('0')
        res.push(n)
        q.push({
            x: cur.x ^ (Math.pow(2, n) - 1),
            s: (cur.s+1)%2
        });
    } else {
        q.push({
            x: cur.x+1,
            s: (cur.s+1)%2
        });
    }

}

print(res.length)
if (res.length > 0) {
    print(res.join(' '))
}

var x = parseInt(readline())

var q = [{ x, s:0}];

var vis = {}, lastx = x, res=[];
while( q.length > 0) {

    var cur = q.shift();

    if ( vis[cur.x] || cur.s > 40) continue;
    vis[cur.x] = true;

    var check = (cur.x+1).toString(2).split('').filter(d=>(d==='1')).length === 1;
    if (check) break;

    lastx = cur.x;
    if (cur.s%2 === 0) {
        var a = cur.x.toString(2);
        n = a.length - a.indexOf('0')
        res.push(n)
        q.push({
            x: cur.x ^ (Math.pow(2, n) - 1),
            s: (cur.s+1)
        });
    } else {
        q.push({
            x: cur.x+1,
            s: (cur.s+1)
        });
    }

}

print(res.length)
if (res.length > 0) {
    print(res.join(' '))
}


/*//deb
var lines = [];
lines[0] = "3 2";
lines[1] = ".*.";
lines[2] = ".*.";
var line = 0;
function readline() {
	return lines[line++];
}*/

function readn() {
	return +readline();
}
function parsens(s) {
	return 	s.split(" ").map(function(x) { return +x; });
}
function sortNumbers(a,b) {
	return a-b;
}

var numbers = parsens(readline());
var w = numbers[0];
var h = numbers[1];

var a = [];
for (var i = 0; i < h; i++) {
	a[i] = [];
	var s = readline();
	for (var j = 0; j < w; j++) {
		if (s.charAt(j) == ".") {
			a[i][j] = 0;
		} else {
			a[i][j] = 1;
		}
	}
}

var b = [];
for (var i = 0; i < w; i++) {
	b[i] = [];
}

for (var i = 0; i < h; i++) {
	for (var j = 0; j < w; j++) {
		b[j][i] = a[i][j];
	}
}

for (var i = 0; i < w; i++) {
	var s = "";
	for (var j = 0; j < h; j++) {
		s += b[i][j] == 0 ? ".." : "**";
	}
	print(s);
	print(s);
}

var size = readline().split(' ');
var w = size[0];
var h = size[1];
var img = [];

for (var i = 0; i < h; i++) {
	img[i] = readline().split('');
}

var rotate = [];

for (var i = 0; i < h; i++) {
	for (var j = 0; j < w; j++) {
		if (!rotate[j]) {
			rotate[j] = [];
		}
		rotate[j][h - i] = img[i][j];
	}
}

var reflection = [];
var height = w;
var width = h;

for (var i = 0; i < height; i++) {
	reflection[i] = [];
	for (var j = 0; j < width; j++) {
		reflection[i][j] = rotate[i][width-j];
	}
}

var scale = [];

for (var i = 0; i < height; i++) {
	scale[2*i] = [];
	scale[2*i + 1] = [];
	for (var j = 0; j < width; j++) {
		var pixel = reflection[i][j];
		scale[2*i][2*j] = pixel;
		scale[2*i][2*j + 1] = pixel;
		scale[2*i + 1][2*j] = pixel;
		scale[2*i + 1][2*j + 1] = pixel;
	}
}

for (var i = 0; i < scale.length; i++) {
	print(scale[i].join(''));
}

var pair = readline().split(' '),
    w = +pair[0],
    h = +pair[1],
    img = [],
    i = 0,
    string;
for (; i < h; i++) {
    img[i] = readline();
}
for (i = 0; i < w; i++) {
    string = img.map(function(str) {
        return str[i] + str[i];
    }).join('');
    print(string);
    print(string);
}

var size = readline().split(' ');
var w = size[0];
var h = size[1];
var img = [];

for (var i = 0; i < h; i++) {
	img[i] = readline().split('');
}

var rotate = [];

for (var i = 0; i < h; i++) {
	for (var j = 0; j < w; j++) {
		if (!rotate[j]) {
			rotate[j] = [];
		}
		rotate[j][h - i] = img[i][j];
	}
}

var reflection = [];
var height = w;
var width = h;

for (var i = 0; i < height; i++) {
	reflection[i] = [];
	for (var j = 0; j < width; j++) {
		reflection[i][j] = rotate[i][width-j];
	}
}

var scale = [];

for (var i = 0; i < height; i++) {
	scale[2*i] = [];
	scale[2*i + 1] = [];
	for (var j = 0; j < width; j++) {
		var pixel = reflection[i][j];
		scale[2*i][2*j] = pixel;
		scale[2*i][2*j + 1] = pixel;
		scale[2*i + 1][2*j] = pixel;
		scale[2*i + 1][2*j + 1] = pixel;
	}
}
print(reflection.length);
print(reflection[0].length);
print(scale.length);
print(scale[0].length);

for (var i = 0; i < scale.length; i++) {
	print(scale[i].join(''));
}

var size = readline().split(' ');
var w = size[0];
var h = size[1];
var img = [];

for (var i = 0; i < h; i++) {
	img[i] = readline().split('');
}

var rotate = [];

for (var i = 0; i < h; i++) {
	for (var j = 0; j < w; j++) {
		if (!rotate[j]) {
			rotate[j] = [];
		}
		rotate[j][h - i] = img[i][j];
	}
}

var reflection = [];
var height = w;
var width = h;
var halfWidth = Math.floor(h/2);

for (var i = 0; i < height; i++) {
	reflection[i] = [];
	for (var j = 0; j < halfWidth; j++) {
		reflection[i][j] = rotate[i][width-j];
		reflection[i][width-j] = rotate[i][j];
	}
}

var scale = [];

for (var i = 0; i < height; i++) {
	scale[2*i] = [];
	scale[2*i + 1] = [];
	for (var j = 0; j < width; j++) {
		var pixel = reflection[i][j];
		scale[2*i][2*j] = pixel;
		scale[2*i][2*j + 1] = pixel;
		scale[2*i + 1][2*j] = pixel;
		scale[2*i + 1][2*j + 1] = pixel;
	}
}

for (var i = 0; i < scale.length; i++) {
	print(scale[i].join(''));
}