// https://codeforces.com/problemset/problem/1620/A

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

const getLine = (function () {
  const getLineGen = (async function* () {
    for await (const line of rl) {
      yield line
    }
  })()
  return async () => {
    let next
    do {
      next = await getLineGen.next()
    } while (!next.done && next.value === '')
    return next.value
  }
})()

let solve = async () => {
  const strLine = parseInt(await getLine())
  for (let i = 0; i < strLine; i++) {
    const str = await getLine()
    if (Array.from(str).filter((x) => x === 'N').length === 1) {
      console.log('NO')
    } else {
      console.log('YES')
    }
  }
  //   process.exit()
  process.stdin.unref()
}

solve()

var t = parseInt(readline());

while(t--) {
	var s = readline();
	if(!/^E*NE*$/.test(s)) {
		print("YES");
	} else {
		print("NO");
	}
}

function solve(input) {
  function reducer(result, c) {
    return result += Number(c === 'N');
  }

  return input.split("").reduce(reducer, 0) !== 1;
}

n = Number(readline());

for (var i = 0; i < n; i++) {
  print(solve(readline()) ? "YES" : "NO");
}

var t = parseInt(readline());

  while (t--) {
    var n = readline();
    var a = 0;

    for (var i = 0; i < n.length; i++) {
      if (n[i] === "N") {
        a++;
      }
    }

    if (a === 1) {
      print("NO");
    } else {
      print("YES");
    }
  }

// https://codeforces.com/problemset/problem/1620/A

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

const getLine = (function () {
  const getLineGen = (async function* () {
    for await (const line of rl) {
      yield line
    }
  })()
  return async () => {
    let next
    do {
      next = await getLineGen.next()
    } while (!next.done && next.value === '')
    return next.value
  }
})()

let solve = async () => {
  const strLine = parseInt(await getLine())
  for (let i = 0; i < strLine; i++) {
    const str = await getLine()

    if (str.indexOf('N') === str.lastIndexOf('N') && str.indexOf('N') != -1) {
      console.log('NO')
    } else {
      console.log('YES')
    }
  }
  //   process.exit()
  process.stdin.unref()
}

solve()

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]
    for(j = 1; j <= n; j++){
        var e = lines[j].split(''), en = 0
        for(l = 0; l < e.length; l++){
            if(e[l] == 'N'){
                en++
            }
        }
        if(en != 1){
            console.log('YES')
        }else{
            console.log('NO')
        }
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
	var t = lines[0];
	var n = 0;
	for(i = 1; i <= t; i++){
        var k = lines[i].split('');
        var a = 0;
        for(j = 0; j < k.length; j++){
            if(k[j] == 'N'){
                a++;
            }
        }
        if(a == 1){
            console.log('NO');
        }else{
            console.log('YES');
        }
	}
});

'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 arr = readLine();
const res = a(arr);
console.log(res)
}
});

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

function a(s){
    let num = 0;
    for(let i = 0 ; i < s.length ; i++){
        if(s[i] == 'N') num++;
    }
    if(num == 1) return 'NO';
    return 'YES';
}

module.exports = a;

'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++];
}

// function foo(x) {
//   process.stdout.write("hello: ");   // without auto '\n' (newline)
//   console.log(x);  // with auto '\n' (newline)
// }

const print = x => {
  process.stdout.write(x);
  process.stdout.write("\n");
};

function main() {
  const n = readline();

  for (let test = 0; test < n; test += 1) {
    const val = readline().split('');

    const m = val.length;

    const currentSet = Array.from({ length: val.length }, ((_, index) => index));

    const unite = pos => {
      if (val[pos] === 'N') {
        return;
      }
      const aSet = currentSet[pos];
      const bSet = currentSet[(pos + 1) % val.length];

      for (let i = 0; i < m; i += 1) {
        if (currentSet[i] === aSet) {
          currentSet[i] = bSet;
        }
      }
    }

    for (let i = 0; i < val.length; i += 1) {
      unite(i);
    }

    let answer = 'YES';

    for (let i = 0; i < val.length; i += 1) {
      if (val[i] === 'E' && currentSet[i] !== currentSet[(i + 1) % val.length]) {
        answer = 'NO';
        break;
      }
      if (val[i] === 'N' && currentSet[i] === currentSet[(i + 1) % val.length]) {
        answer = 'NO';
        break;
      }
    }

    print(answer);
  }

}

// tmplate input and output

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++];
}

function readints() {
    return readline().split(' ').map(num => parseInt(num));
}

function run_case() {
    S = readline();
    let countN = 0;

    for (c of S)
        countN += c == 'N'

    console.log(countN == 1 ? "NO" : "YES");
}

function main() {
    let tt = parseInt(readline());

    while (tt--)
        run_case();
}

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

let inputString = '';

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

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

    main(inputString);
});

function log(message){
    if(process.env.NODE_ENV === "debug"){
        console.log(message);
    }
}

function main(fileContents) {//input lines as an array
    // console.log(fileContents);
    fileContents.splice(0,1);

    //if all is equal except for the first/last one thats the only false scenario
    fileContents.forEach(scenario => {
        const countE = scenario.split("").filter(l => l!="N").length
        const countN = scenario.split("").filter(l => l!="E").length
        // console.log("scenario", scenario, countE, countN)
        if(countN === 1){
            console.log("NO")
        }else{
            console.log("YES")
        }
    })

}

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++];
}

function main() {
    let [t] = readline().split(' ').map(num => parseInt(num));
    for (let i = 0; i < t; i++) {
        let s = readline();
        let c = 0;
        for (let j = 0; j < s.length; j++) {
            c = s[j] === 'N' ? c + 1 : c;
        }
        console.log(c === 1 ? 'NO' : 'YES');
    }
}

     var len = readline();
     var inputData="";
    for(var i=0;i<+len;i++)
    {
    inputData = readline();
    if(inputData.split('N').length-1 ==1)
     print("NO");
       else
      print("YES");
    }

     var len = readline();
     var inputData="";
    //  let resultArr=[];
    for(var i=0;i<+len;i++)
    {
    inputData = readline();
     //if(inputData[0]==inputData[inputData.length-1])
    if(inputData.split('N').length-1 ==1)
     print("NO");
       else
      print("YES");
    }

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                    let s = readline();
                    var c = 0;
                    for(var i=0;i<s.length;i++) {
                        if(s[i] == 'N') c++;
                    }
                    if(c == 1) console.log('NO')
                    else console.log('YES')
}

k = parseInt(readline()) ;
while (k--) {
	s = readline () ;
	cnt = 0 ;
	for (i = 0 ; i <s.length ; i ++ )
		 if (s[i] =='N') cnt ++ ;

	ok = true ;
	ok &= cnt != 1  ;
	(ok)? print("YES"): print("NO");
}
// ENNEENE 1101101 0112

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                    let s = readline();
                    var c = 0;
                    for(var i=1;i<=s.length;i++) {
                        if(s[i] == 'N') c++;
                    }
                    if(c == 1) console.log('NO')
                    else console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline();
                var c = 0;
                for(var i=0;i<s.length;i++) {
                    if(s[i] == 'N') c++;
                }
                if(c == 1) console.log('NO')
                else console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline().split('');
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                var n = false;
                n = s[s.length-1]=='\r';
                for(var i=0;n ? i<s.length-1 : i<s.length;i++) {
                	if(s[i] == 'N') c++;
                }
                for(var i=0;n ? i<s.length-1 : i<s.length;i++) {
                	if(n ? i < s.length-2 : i < s.length-1) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

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

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline().split('');
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                console.log(s[s.length-1]=='\r')
                for(var i=0;i<s.length;i++) {
                	if(s[i] == 'N') c++;
                }
                for(var i=0;i<s.length;i++) {
                	if(i < s.length-1) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

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

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline().split('');
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length;i++) {
                	if(s[i] == 'N') c++;
                }
                //console.log(s.length)
                for(var i=0;i<s.length;i++) {
                    //console.log(s[i], i)
                	if(i < s.length-1) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

                	}
                }
                s[s.length-1] == '\r' ? console.log(s) : console.log('t')
                console.log(s[s.length-1])
                y || s.length <= 1 ? console.log('YES') : console.log('NO');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline().split('');
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length;i++) {
                	if(s[i] == 'N') c++;
                }
                //console.log(s.length)
                for(var i=0;i<s.length;i++) {
                    //console.log(s[i], i)
                	if(i < s.length-1) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

                	}
                }
                console.log(s)
                console.log(s[s.length-1])
                y || s.length <= 1 ? console.log('YES') : console.log('NO');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline().split('');
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length;i++) {
                	if(s[i] == 'N') c++;
                }
                //console.log(s.length)
                for(var i=0;i<s.length;i++) {
                    //console.log(s[i], i)
                	if(i < s.length-1) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

                	}
                }
                console.log(s[s.length-2])
                console.log(s[s.length-1])
                y || s.length <= 1 ? console.log('YES') : console.log('NO');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline();
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length;i++) {
                	if(s[i] == 'N') c++;
                }
                //console.log(s.length)
                for(var i=0;i<s.length;i++) {
                    //console.log(s[i], i)
                	if(i < s.length-1) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

                	}
                }
                console.log(s[s.length-1])
                console.log(a)
                y || s.length <= 1 ? console.log('YES') : console.log('NO');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline().split(' ');
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length;i++) {
                	if(s[i] == 'N') c++;
                }
                //console.log(s.length)
                for(var i=0;i<s.length;i++) {
                    //console.log(s[i], i)
                	if(i < s.length-1) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

                	}
                }
                console.log(s)
                y || s.length <= 1 ? console.log('YES') : console.log('NO');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline().split(' ');
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length;i++) {
                	if(s[i] == 'N') c++;
                }
                //console.log(s.length)
                for(var i=0;i<s.length;i++) {
                    //console.log(s[i], i)
                	if(i < s.length-1) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

                	}
                }
                //console.log(a)
                y || s.length <= 1 ? console.log('YES') : console.log('NO');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline().split('');
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length;i++) {
                	if(s[i] == 'N') c++;
                }
                //console.log(s.length)
                for(var i=0;i<s.length;i++) {
                    //console.log(s[i], i)
                	if(i < s.length-1) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

                	}
                }
                console.log(s)
                y || s.length <= 1 ? console.log('YES') : console.log('NO');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline().split('');
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length;i++) {
                	if(s[i] == 'N') c++;
                }
                //console.log(s.length)
                for(var i=0;i<s.length;i++) {
                    //console.log(s[i], i)
                	if(i < s.length-1) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

                	}
                }
                //console.log(a)
                y || s.length <= 1 ? console.log('YES') : console.log('NO');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline();
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length-1;i++) {
                	if(s[i] == 'N') c++;
                }
                //console.log(s.length)
                for(var i=0;i<s.length-1;i++) {
                    //console.log(s[i], i)
                	if(i < s.length-2) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

                	}
                }
                //console.log(a)
                y || s.length <= 2 ? console.log('YES') : console.log('NO');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline();
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length-1;i++) {
                	if(s[i] == 'N') c++;
                }
                console.log(s.length)
                for(var i=0;i<s.length-1;i++) {
                    console.log(s[i], i)
                	if(i < s.length-2) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

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

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline();
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length-1;i++) {
                	if(s[i] == 'N') c++;
                }
                console.log(s.length)
                for(var i=0;i<s.length-1;i++) {
                    console.log(s[i], i)
                	if(i < s.length-2) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

                	}
                }
                console.log(s.length)
                y ? console.log('YES') : console.log('NO');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline();
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length-1;i++) {
                	if(s[i] == 'N') c++;
                }
                for(var i=0;i<s.length-1;i++) {
                    //console.log(s[i])
                	if(i < s.length-2) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                		    r++;
                			if(r == c) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

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

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
                let s = readline();
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length-1;i++) {
                	if(s[i] == 'N') c++;
                }
                for(var i=0;i<s.length-1;i++) {
                    //console.log(s[i])
                	if(i < s.length-2) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                			if(r == c-1) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                			r++;
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

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

        const fs = require('fs');
        const input = fs.readFileSync(0, 'utf8').trim().split('\n');
        let currentline = 0;
        function readline(){
                return input[currentline++];
        }
        var T = readline();
        for(var q=1;q<=T;q++) {
                let s = readline();
                var c = 0;
                var r = 0;
                var a = []
                var y = false;
                a[0] = 1;
                for(var i=0;i<s.length;i++) {
                	if(s[i] == 'N') c++;
                }
                for(var i=0;i<s.length;i++) {
                    //console.log(s[i])
                	if(i < s.length-1) {
                		if(s[i] == 'E') {
                			a[i+1] = a[i];
                		} else {
                			if(r == c-1) {
                				a[i+1] = a[0]
                			} else {
                				a[i+1] = a[i]+1;
                			}
                			r++;
                		}
                	} else {
                		if(s[i] == 'E' && a[i] == a[0]) {
                			y = true;
                		} else if(s[i] == 'N' && a[i] !== a[0]) {
                			y = true;
                		} else {
                			y = false;
                		}

                	}
                }
                console.log(s.length)
                y ? console.log('YES') : console.log('NO');
        }

    const fs = require('fs');
    const input = fs.readFileSync(0, 'utf8').trim().split('\n');
    let currentline = 0;
    function readline(){
            return input[currentline++];
    }
    var T = readline();
    for(var q=1;q<=T;q++) {
            let s = readline();
            var c = 0;
            var r = 0;
            var a = []
            var y = false;
            a[0] = 1;
            for(var i=0;i<s.length;i++) {
            	if(s[i] == 'N') c++;
            }
            for(var i=0;i<s.length;i++) {
                //console.log(s[i])
            	if(i < s.length-1) {
            		if(s[i] == 'E') {
            			a[i+1] = a[i];
            		} else {
            			if(r == c-1) {
            				a[i+1] = a[0]
            			} else {
            				a[i+1] = a[i]+1;
            			}
            			r++;
            		}
            	} else {
            		if(s[i] == 'E' && a[i] == a[0]) {
            			y = true;
            		} else if(s[i] == 'N' && a[i] !== a[0]) {
            			y = true;
            		} else {
            			y = false;
            		}

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

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
        return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let s = readline();
        var c = 0;
        var r = 0;
        var a = []
        var y = false;
        a[0] = 1;
        for(var i=0;i<s.length;i++) {
        	if(s[i] == 'N') c++;
        }
        for(var i=0;i<s.length;i++) {
            //console.log(s[i])
        	if(i < s.length-1) {
        		if(s[i] == 'E') {
        			a[i+1] = a[i];
        		} else {
        			if(r == c-1) {
        				a[i+1] = a[0]
        			} else {
        				a[i+1] = a[i]+1;
        			}
        			r++;
        		}
        	} else {
        		if(s[i] == 'E' && a[i] == a[0]) {
        			y = true;
        		} else if(s[i] == 'N' && a[i] !== a[0]) {
        			y = true;
        		} else {
        			y = false;
        		}

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

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
        return input[currentline++];
}
var T = readline();
for(var q =1;q<=T;q++) {
        var s = readline();
        var c = 0;
        var r = 0
        var a = []
        var y = false;
        a[0] = 1;
        for(var i=0;i<s.length;i++) {
        	if(s[i] == 'N') c++;
        	//else c[1]++;
        }
        for(var i=0;i<s.length;i++) {
            console.log(s[i])
        	if(i < s.length-1) {
        		if(s[i] == 'E') {
        			a[i+1] = a[i];
        			//r++;
        		} else {
        			if(r == c-1) {
        				a[i+1] = a[0]
        			} else {
        				a[i+1] = a[i]+1;
        			}
        			r++;
        		}
        	} else {
        		if(s[i] == 'E' && a[i] == a[0]) {
        			y = true;
        		} else if(s[i] == 'N' && a[i] !== a[0]) {
        			y = true;
        		} else {
        			y = false;
        		}

        	}
        }
        if(y) console.log('Yes');
        else console.log('NO');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                    return input[currentline++];
}
var T = readline();
for(var q =1;q<=T;q++) {
        var s = readline();
        var c = 0;
        var r = 0
        var a = []
        var y = false;
        a[0] = 1;
        for(var i=0;i<s.length;i++) {
        	if(s[i] == 'N') c++;
        	//else c[1]++;
        }
        for(var i=0;i<s.length;i++) {
        	if(i < s.length-1) {
        		if(s[i] == 'E') {
        			a[i+1] = a[i];
        			r++;
        		} else {
        			if(r == c-1) {
        				a[i+1] = a[0]
        			} else {
        				a[i+1] = a[i]+1;
        			}
        		}
        	} else {
        		if(s[i] == 'E' && a[i] == a[0]) {
        			y = true;
        		} else if(s[i] == 'N' && a[i] !== a[0]) {
        			y = true;
        		} else {
        			y = false;
        		}

        	}
        }
        if(y) console.log('YES')
        else console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                    return input[currentline++];
}
var T = readline();
for(var q =1;q<=T;q++) {
        var s = readline()
        var c = 0;
        var r = 0
        var a = []
        var y = false;
        a[0] = 1;
        for(var i=0;i<s.length;i++) {
        	if(s[i] == 'E') c++;
        	else c[1]++;
        }
        for(var i=0;i<s.length;i++) {
        	if(i < s.length-1) {
        		if(s[i] == 'E') {
        			a[i+1] = a[i];
        			r++;
        		} else {
        			if(r == c-1) {
        				a[i+1] = a[0]
        			} else {
        				a[i+1] = a[i]+1;
        			}
        		}
        	} else {
        		if(s[i] == 'E' && a[i] == a[0]) {
        			y = true;
        		} else if(s[i] == 'N' && a[i] !== a[0]) {
        			y = true;
        		} else {
        			y = false;
        		}

        	}
        }
        console.log(s)
        if(y) console.log('Yes')
        else console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                    return input[currentline++];
}
var T = readline();
for(var q =1;q<=T;q++) {
        var s = readline()
        var c = 0;
        var r = 0
        var a = []
        var y = false;
        a[0] = 1;
        for(var i=0;i<s.length;i++) {
        	if(s[i] == 'E') c++;
        	else c[1]++;
        }
        for(var i=0;i<s.length;i++) {
        	if(i < s.length-1) {
        		if(s[i] == 'E') {
        			a[i+1] = a[i];
        			r++;
        		} else {
        			if(r == c-1) {
        				a[i+1] = a[0]
        			} else {
        				a[i+1] = a[i]+1;
        			}
        		}
        	} else {
        		if(s[i] == 'E' && a[i] == a[0]) {
        			y = true;
        		} else if(s[i] == 'N' && a[i] !== a[0]) {
        			y = true;
        		} else {
        			y = false;
        		}

        	}
        }
        if(y) console.log('Yes')
        else console.log('NO')
}

// https://codeforces.com/problemset/problem/1620/A

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

const getLine = (function () {
  const getLineGen = (async function* () {
    for await (const line of rl) {
      yield line
    }
  })()
  return async () => {
    let next
    do {
      next = await getLineGen.next()
    } while (!next.done && next.value === '')
    return next.value
  }
})()

let solve = async () => {
  const strLine = parseInt(await getLine())
  for (let i = 0; i < strLine; i++) {
    const str = await getLine()
    if (str.indexOf('N') === str.lastIndexOf('N')) {
      console.log('NO')
    } else {
      console.log('YES')
    }
  }
  //   process.exit()
  process.stdin.unref()
}

solve()

// https://codeforces.com/problemset/problem/1620/A

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

const getLine = (function () {
  const getLineGen = (async function* () {
    for await (const line of rl) {
      yield line
    }
  })()
  return async () => {
    let next
    do {
      next = await getLineGen.next()
    } while (!next.done && next.value === '')
    return next.value
  }
})()

let solve = async () => {
  const strLine = parseInt(await getLine())
  for (let i = 0; i < strLine; i++) {
    const str = await getLine()
    if (str[0] === str[str.length - 1]) {
      console.log('YES')
    } else {
      console.log('NO')
    }
  }
  //   process.exit()
  process.stdin.unref()
}

solve()

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], en = 0
    for(j = 1; j <= n; j++){
        var e = lines[j].split('')
        for(l = 0; l < e.length; l++){
            if(e[l] == 'N'){
                en++
            }
        }
        if(en != 1){
            console.log('YES')
        }else{
            console.log('NO')
        }
    }
});

 var len = readline();
 var inputData="";
//  let resultArr=[];
for(var i=0;i<+len;i++)
{
inputData = readline();
 if(inputData[0]==inputData[inputData.length-1])
 print("YES");
   else
  print("NO");
}
//print(inputData);

 var len = readline();
 var inputData="";
//  let resultArr=[];
for(var i=0;i<+len;i++)
{
inputData = readline();

}
print(inputData);
//inputData.push(readline());
// if(inputData[0]==inputData[(inputData.length)-1])
//  print("YES");
//    else
//  print("NO");

 var len = readline();
 var inputData=[];
//  let resultArr=[];
for(var i=0;i<+len;i++)
{
print("YES");
}
print(len);
//inputData.push(readline());
// if(inputData[0]==inputData[(inputData.length)-1])
//  print("YES");
//    else
//  print("NO");

                    var len = readline();
                    var inputData=[];
                  //  let resultArr=[];

                   // for(let i=0;i<len.praseInt();i++)
                 //   {
                   //     inputData.push(readline());
                       // if(inputData[0]==inputData[(inputData.length)-1])
                      //  print("YES");
                    //    else
                      //  print("NO");
                  //  }
                    print(+len);

                    var len = readline();
                    var inputData=[];
                  //  let resultArr=[];

                   // for(let i=0;i<len.praseInt();i++)
                 //   {
                   //     inputData.push(readline());
                       // if(inputData[0]==inputData[(inputData.length)-1])
                      //  print("YES");
                    //    else
                      //  print("NO");
                  //  }
                    print(len);

                var len = readline();
                var inputData=[];
              //  let resultArr=[];

              //  for(let i=0;i<len.praseInt();i++)
            //    {
                    inputData.push(readline());
                   // if(inputData[0]==inputData[(inputData.length)-1])
                  //  print("YES");
                //    else
                  //  print("NO");
               // }
                print(inputData,len);

        var len= readline();
        var inputData="";
      //  let resultArr=[];

       // for(int i=0;i<+len;i++)
        //{
            inputData= readline();
            if(inputData[0]==inputData[(inputData.length)-1])
            print("YES");
            else
            print("NO");
        //}
       // print(resultArr.join('\n'));

        var length= readline();
        var inputData = readline();
        print(inputData);

        var inputData= readline();
        print(inputData);

    var inputData= readline().split('\n');
    print(inputData);

k = parseInt(readline()) ;
while (k--) {
	s = readline () ;
	sm = [] ;
	sm[0] = s[0] ;
 	for (i= 1 ; i <s.length ; i ++ )
 		if (s[i] != sm[sm.length -1 ] ) sm += s[i] ;

	(s != "EN" && s != "NE" && s!= "ENE" && sm != "EN" &&
		sm != "NE" )?print("YES"):
	print("NO") ;
}

k = parseInt(readline()) ;
while (k--) {
	s = readline () ;
	sm = [] ;
	sm[0] = s[0] ;

	(s != "EN" && s != "NE" && s!= "ENE" && sm != "EN" &&
		sm != "NE" )?print("YES"):
	print("NO") ;
}

k = parseInt(readline()) ;
while (k--) {
	s = readline () ;
	sm = [] ;
	sm[0] = s[0] ;
	for (i = 1 ;i < s.length ; i ++ ) if (s[i] != sm[sm.length -1]) sm += s[i] ;

lon = (s[0] == 'N') ;
for (i = 1 ; i < s.length ; i ++ ) lon &= s[i] == 'E';
	(s != "EN" && s != "NE" && s!= "ENE" && sm != "EN" && !lon )?print("YES"):
	print("NO") ;
}

k = parseInt(readline()) ;
while (k--) {
	s = readline () ;
	sm = [] ;
	sm[0] = s[0] ;
	for (i = 1 ;i < s.length ; i ++ ) if (s[i] != sm[sm.length -1]) sm += s[i] ;

lon = (s[i] == 'N') ;
for (i = 1 ; i < s.length ; i ++ ) lon &= s[i] == 'E';
	(s != "EN" && s != "NE" && s!= "ENE" && sm != "EN" && !lon )?print("YES"):
	print("NO") ;
}

k = parseInt(readline()) ;
while (k--) {
	s = readline () ;
	sm = [] ;
	sm[0] = s[0] ;
	for (i = 1 ;i < s.length ; i ++ ) if (s[i] != sm[sm.length -1]) sm += s[i] ;

	(s != "EN" && s != "NE" && s!= "ENE" && sm != "EN" )?print("YES"):
	print("NO") ;
}

k = parseInt(readline()) ;
while (k--) {
	s = readline () ;
	(s != "EN" && s != "NE" && s!= "ENE" )?print("YES"):
	print("NO") ;
}

k = parseInt(readline()) ;
while (k--) {
	s = readline () ;

	(s != "EN" && s != "NE" && s!= "ENE" )?print("NO"):print("YES") ;

}

k = parseInt(readline()) ;
while (k--) {
	s = readline () ;
	sm = [] ;
	sm[0] = s[0] ;
	for ( i = 1 ; i<s.length ; i ++ ){
		if (s[i] != sm[sm.length-1]) sm += s[i] ;

	}
	(sm != "EN" && sm != "NE" && sm!= "ENE" )?print("YES"):print("NO") ;

}

var t = parseInt(readline());

while(t--) {
	var s = readline();
	if(!/E*NE*/.test(s)) {
		print("YES");
	} else {
		print("NO");
	}
}

function solve(input) {
  function reducer(result, c, i) {
    if (!result) return result;
    if (i === 0) {
      arr.push(0);
      return result;
    }

    if (i === input.length - 1) {
      if (c === "N") {
        if (input[i - 1] === "N") {
          arr.push(arr[i - 1] + 1);
          return arr[i - 1] !== arr[i] && arr[i] !== arr[0];
        } else {
          arr.push(arr[i - 1]);
          return arr[i - 1] === arr[i] && arr[i] !== arr[0];
        }
      } else {
        arr.push(arr[0]);
        return input[i - 1] === "N"
          ? arr[i - 1] !== arr[i]
          : arr[i - 1] === arr[i];
      }
    }

    if (c === "N") {
      arr.push(arr[i - 1] + 1);
    } else {
      arr.push(arr[i - 1]);
    }

    return result;
  }

  var arr = [];

  return input.split("").reduce(reducer, true);
}

n = Number(readline());

for (var i = 0; i < n; i++) {
  print(solve(readline()) ? "YES" : "NO");
}

function solve(input) {
  function reducer(result, c, i) {
    if (!result) return result;

    if (i === input.length - 1) {
      if (c === "N") {
        if (input[i - 1] === "N") {
          arr.push(arr[i - 1] + 1);
          return arr[i - 1] !== arr[i] && arr[i] !== arr[0];
        } else {
          arr.push(arr[i - 1]);
          return arr[i - 1] === arr[i] && arr[i] !== arr[0];
        }
      } else {
        arr.push(arr[0]);
        return input[i - 1] === "N"
          ? arr[i - 1] !== arr[i]
          : arr[i - 1] === arr[i];
      }
    }

    if (c === "N") {
      arr.push(arr[i - 1] + 1);
    } else {
      arr.push(arr[i - 1]);
    }

    return result;
  }

  var arr = [];

  return input.split("").reduce(reducer, true);
}

n = Number(readline());

for (var i = 0; i < n; i++) {
  print(solve(readline()) ? "YES" : "NO");
}


(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const p="local"===process.argv[2],f=t=>{if(p){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(" ").map((t=>parseFloat(t)))}function c(){return a().split("")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t]=i.default.nextNumbers(),e=i.default.nextNumbers(),r=[],n=Array(t+1).fill(0),o=e[0],s=!0;for(let r=0;r<t;++r)e[r]!=o&&(s=!1);r.push(e[0]);for(let n=1;n<t;++n)e[n]!=e[n-1]&&r.push(e[n]);let u=r.length;for(let t=0;t<u;++t)n[r[t]]++;if(s)return void i.default.puts(0);if(1==n[r[0]])return void i.default.puts(1);let l=t;for(let t=0;t<u;++t){let e=n[r[t]]+1;r[0]==r[t]&&e--,r[u-1]==r[t]&&e--,l=[l,e].min()}i.default.puts(l)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let b: number[] = []
//
//   let cnt = Array(n + 1).fill(0)
//
//   let x = a[0]
//
//   let allEq = true
//
//   for (let i = 0; i < n; ++i) {
//     if (a[i] != x) {
//       allEq = false
//     }
//   }
//
//   b.push(a[0])
//
//   for (let i = 1; i < n; ++i) {
//     if (a[i] != a[i - 1]) {
//       b.push(a[i])
//     }
//   }
//
//   // io.debug(b)
//
//   let m = b.length
//
//   for (let i = 0; i < m; ++i) {
//     cnt[b[i]]++
//   }
//
//   if (allEq) {
//     io.puts(0)
//     return
//   }
//
//   if (cnt[b[0]] == 1) {
//     io.puts(1)
//     return
//   }
//
//   let best = n
//
//   for (let i = 0; i < m; ++i) {
//     let candidate = cnt[b[i]] + 1
//
//     if (b[0] == b[i]) {
//       candidate--
//     }
//
//     if (b[m - 1] == b[i]) {
//       candidate--
//     }
//
//     best = [best, candidate].min()
//   }
//
//   io.puts(best)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

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 A(){
    let t = pi(readline());
    while(t){
        t--;
        let n = pi(readline());
        let res = '';
        for(let i = 1; i <= n; i++){
            if(i !== n){
                res += ` ${i+1}`;
            }else{
                res += ` ${1}`;
            }
        }

        console.log(res.trim());
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let x = readline().split(' ');
        let a = new Array(n);
        let max = 0;
        for(let i = 0; i < n; i++)
            max = Math.max(max, pi(x[i]));
        let map = new Array(max+2);
        let rMap = new Array(max+2);

        for(let i = 0; i < n; i++){
            a[i] = pi(x[i]);
            if(map[a[i]] !== undefined){
                map[a[i]] += 1;
                rMap[a[i]] = i;
            }else{
                map[a[i]]  = 1;
                rMap[a[i]] = i;
            }
        }

        let min = 99999999999;
        for(let i = 0; i < a.length; i++){
            if(map[a[i]] === 1){
                min = Math.min(min, a[i]);
            }
        }

        console.log(min === 99999999999 ? -1 : rMap[min]+1);
    }
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        let max = 0;
        for(let i = 0; i < n; i++)
            max = Math.max(max, a[i]);
        let map = new Array(max + 2);
        //map.fill(0);
        for(let i = 0; i < n; i++){
            if(i === 0){
                map[a[i]] = 1;
                continue;
            }

            if(a[i] !== a[i-1]){
                if(map[a[i]] !== undefined){
                    map[a[i]] += 1;
                }else{
                    map[a[i]]  = 1;
                }
            }
        }

        let min = 99999999;
        for(let i = 0; i < n; i++){
            if(map[a[i]] !== undefined){
                if(a[i] === a[0] && a[i] === a[n-1]){
                    min = Math.min(min, map[a[i]]-1);
                }else if(a[i] === a[0] || a[i] === a[n-1]){
                    min = Math.min(min, map[a[i]]);
                }else{
                    min = Math.min(min, map[a[i]]+1);
                }
            }
        }

        console.log(min === 99999999 ? 0 : min);
    }
}

let getFactors = (n) => {
    let i = 2;
    let res = [];
    while(i*i <= n){
        if(n%i === 0)
            res.push([i,n/i]);
        i++;
    }
    return res;
}

function D(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let dp = new Array(Math.floor(n+1));
        dp.fill(1);

        for(let i = 0; i < dp.length; i++){
            let f = getFactors(i);
            if(f.length !== 0){
                for(let j = 0; j < f.length; j++){
                    if(f[j][1] % f[j][0] === 0)
                        dp[i] = Math.max(dp[i], dp[f[j][0]]+dp[f[j][1]]);
                }
            }
        }

        let f = getFactors(n);
        let max = 1;
        if(f.length > 0){
            for(let i = 0; i < f.length; i++){
                if(f[i][1] % f[i][0] === 0)
                    max = Math.max(max, dp[f[i][0]]+dp[f[i][1]]);
            }
        }
        console.log(max);
    }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine().split(" ").map(Number);
    const map = new Map();

    for (let i = 0; i < len; i++) {
      const n = arr[i];
      if (map.has(n)) {
        let { index, count, frequency } = { ...map.get(n) };
        map.set(n, { index: i, count, frequency: frequency + 1 });
        if (Math.abs(index - i) > 1) {
          map.set(n, { index: i, count: count + 1 });
        }
      } else {
        if (i > 0) {
          map.set(n, { count: 1, index: i, frequency: 1 });
        } else {
          map.set(n, { count: 0, index: i, frequency: 1 });
        }
      }
    }
    let [min, maxFrequence] = [Infinity, 0];
    for (let [key, obj] of map) {
      let { count, index, frequency } = obj;
      if (index !== len - 1) count++;
      min = Math.min(min, count);
      maxFrequence = Math.max(maxFrequence, frequency);
    }

    if (len === 1) console.log(0);
    else if (maxFrequence === 1) console.log(1);
    else console.log(min);
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
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 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';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//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();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		var map = {};
		for(var j = 0; j < N; j++){
			if(map[list[j]] == null){
				map[list[j]] = [];
			}
			map[list[j]].push(j);
		}

		var keys = Object.keys(map);
		var count = N + 1;
		if(keys.length == 1){
			count = 0;
		}
		for(var j = 0; j < keys.length; j++){
			var check = map[keys[j]];
			var tmpCount = 0;
			if(check[0] != 0){
				tmpCount++;
			}
			if(check[check.length - 1] != N - 1){
				tmpCount++;
			}
			for(var k = 0; k < check.length - 1; k++){
				if(check[k] + 1 != check[k + 1]){
					tmpCount++;
				}
			}
			count = Math.min(count, tmpCount);
		}
		output[i] = count;
	}
	myout(myconv(output, 9));
}

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

let stdinInput = '';

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

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 2;
    let i = 1;

    while (i <= testCases) {
      const s = data[i + 1].trim().split(' ').map(Number);
      // let a = data[i].trim() * 1;
      const n = data[i] * 1;
      // const p = BigInt(s[0]);
      // const q = BigInt(s[1]);
      // s.sort((a, b) => b - a);
      let obj = {};
      // console.log(s);
      // let first = true;

      for (let j = 0; j < n; j += 1) {
        if (obj[s[j]]) obj[s[j]].push(j);
        else {
          obj[s[j]] = [j];
          // obj[s[j]]['count'] = 1;
          // obj[s[j]]['index'] = j + 1;
        }
      }

      let uq = false;
      let idx = Number.MAX_SAFE_INTEGER;
      // console.log(obj);

      for (let key in obj) {
        if (obj[key].length > 1) uq = true;
        if (obj[key].length === n) {idx = 0; break;}
        let temp = 0;
          if (obj[key][0] > 0) temp += 1;
          for (let j = 1; j < obj[key].length; j += 1) {
            if (obj[key][j] - obj[key][j - 1] > 1) temp += 1;
          }
          if (obj[key][obj[key].length - 1] < n - 1) temp += 1;
        idx = Math.min(idx, temp);
      }

      if (n === 1) console.log(0);
      else console.log(uq ? idx : 1);
      i += 2;
    }

}

"use strict";

(() => {

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

    let curLine = 0, allLines = [];

    let nextLine = () => {
        if(curLine == allLines.length) throw new ReferenceError("No more input in the buffer");
        return allLines[curLine++]
    };

    readline.on("line", line => { allLines.push(line); });
    readline.on("close", () => { main(nextLine) });

})();

function main(nextLine) {
    let t = Number(nextLine());

    while(t--) {
        let n = Number(nextLine());
        let ara = nextLine().split(" ").map(x => Number(x));

        let ase = new Array(n+1).fill(false), cnt = new Array(n+1).fill(0);

        ara.forEach((element, index) => {
            ase[element] = true;
            if(index && ara[index] !== ara[index-1]) cnt[element]++;
        });

        let mn = n;
        for(let i = 1; i <= n; i++) {
            if(ase[i]) mn = Math.min(mn, cnt[i]+(ara[n-1] !== i));
        }

        console.log(mn);
    }
}

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

let lines = [];

rl.on('line', (data) => {
    lines.push(data);
    if(lines.length > 0 && 2 * parseInt(lines[0]) === lines.length - 1) {
	rl.close();
	main();
    }
});

async function main() {
    let t = parseInt(lines[0]);
    for(let i = 1; i <= 2 * t; i += 2) {
	let n = parseInt(lines[i]);
	const arr = lines[i + 1].split(' ').map(x => parseInt(x));

	let map = {};
	for(const val of arr) {
	    map[val] = 1;
	}

	for(let j = 1; j < n; j++) {
	    if(arr[j] != arr[j - 1])
		map[arr[j]]++;
	}

	map[arr[n - 1]]--;
	let ans = 9999999;
	for(const v in map) {
	    ans = Math.min(ans, map[v]);
	}

	console.log(ans);
    }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine().split(" ").map(Number);
    const map = new Map();

    for (let i = 0; i < len; i++) {
      const n = arr[i];
      if (map.has(n)) {
        let { index, count, frequency } = { ...map.get(n) };
        map.set(n, { index: i, count, frequency: frequency + 1 });
        if (Math.abs(index - i) > 1) {
          map.set(n, { index: i, count: count + 1 });
        }
      } else {
        if (i > 0) {
          map.set(n, { count: 1, index: i, frequency: 1 });
        } else {
          map.set(n, { count: 0, index: i, frequency: 1 });
        }
      }
    }
    let [min, maxFrequence] = [Infinity, 0];
    for (let [key, obj] of map) {
      let { count, index, frequency } = obj;
      if (index !== len - 1) count++;
      min = Math.min(min, count);
      maxFrequence = Math.max(maxFrequence, frequency);
    }

    if (maxFrequence === 1) console.log(1);
    else console.log(min);
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
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 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';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//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();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		var map = {};
		var isZero = -1;
		for(var j = 0; j < N; j++){
			if(j == 0){
				isZero = list[j];
			}
			if(map[list[j]] == null){
				map[list[j]] = [j];
			}else{
				if(map[list[j]][map[list[j]].length - 1] == j - 1){
					map[list[j]][map[list[j]].length - 1] = j;
				}else{
					map[list[j]].push(j);
				}
			}
		}

		var keys = Object.keys(map);
		var count = N + 1;
		if(keys.length == 1){
			count = 0;
		}
		for(var j = 0; j < keys.length; j++){
			var check = map[keys[j]];
			if(check.length == 1){
				if(check[0] == 0 || check[0] == N - 1){
					count = Math.min(count, 1);
				}else{
					count = Math.min(count, 2);
				}
			}else{
				var tmpCount = 0;
				if(check[0] == 0 || isZero == keys[j]){

				}else{
					tmpCount++;
				}
				if(check[check.length - 1] != N - 1){
					tmpCount++;
				}
				tmpCount += check.length - 1;
				count = Math.min(count, tmpCount);
			}
		}
		output[i] = count;
	}
	myout(myconv(output, 9));
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
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 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';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//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();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		var map = {};
		var isZero = -1;
		for(var j = 0; j < N; j++){
			if(j == 0){
				isZero = list[j];
			}
			if(map[list[j]] == null){
				map[list[j]] = [j];
			}else{
				if(map[list[j]][map[list[j]].length - 1] == j - 1){
					map[list[j]][map[list[j]].length - 1] = j;
				}else{
					map[list[j]].push(j);
				}
			}
		}

		var keys = Object.keys(map);
		var count = N + 1;
		if(keys.length == 1){
			count = 0;
		}
		for(var j = 0; j < keys.length; j++){
			var check = map[keys[j]];
			if(check.length == 1){
				if(check[0] == 0 || check[0] == N - 1){
					count = Math.min(count, 1);
				}else{
					count = Math.min(count, 2);
				}
			}else{
				var tmpCount = 0;
				if(check[0] == 0 || isZero != keys[j]){

				}else{
					tmpCount++;
				}
				if(check[check.length - 1] != N - 1){
					tmpCount++;
				}
				tmpCount += check.length - 1;
				count = Math.min(count, tmpCount);
			}
		}
		output[i] = count;
	}
	myout(myconv(output, 9));
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
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 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';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//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();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		var map = {};
		for(var j = 0; j < N; j++){
			if(map[list[j]] == null){
				map[list[j]] = [j];
			}else{
				if(map[list[j]][map[list[j]].length - 1] == j - 1){
					map[list[j]][map[list[j]].length - 1] = j;
				}else{
					map[list[j]].push(j);
				}
			}
		}

		var keys = Object.keys(map);
		var count = N + 1;
		if(keys.length == 1){
			count = 0;
		}
		for(var j = 0; j < keys.length; j++){
			var check = map[keys[j]];
			if(check.length == 1){
				if(check[0] == 0 || check[0] == N - 1){
					count = Math.min(count, 1);
				}else{
					count = Math.min(count, 2);
				}
			}else{
				var tmpCount = 0;
				if(check[0] != 0){
					tmpCount++;
				}
				if(check[check.length - 1] != N - 1){
					tmpCount++;
				}
				tmpCount += check.length - 1;
				count = Math.min(count, tmpCount);
			}
		}
		output[i] = count;
	}
	myout(myconv(output, 9));
}

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

let stdinInput = '';

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

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 2;
    let i = 1;

    while (i <= testCases) {
      const s = data[i + 1].trim().split(' ').map(Number);
      // let a = data[i].trim() * 1;
      const n = data[i] * 1;
      // const p = BigInt(s[0]);
      // const q = BigInt(s[1]);
      // s.sort((a, b) => b - a);
      let obj = {};
      // console.log(s);
      // let first = true;

      for (let j = 0; j < n; j += 1) {
        if (obj[s[j]]) obj[s[j]].push(j);
        else {
          obj[s[j]] = [j];
          // obj[s[j]]['count'] = 1;
          // obj[s[j]]['index'] = j + 1;
        }
      }

      let uq = false;
      let idx = Number.MAX_SAFE_INTEGER;
      // console.log(obj);

      for (let key in obj) {
        if (obj[key].length > 1) uq = true;
        if (obj[key].length === n) {idx = 0; break;}
        let temp = 0;
          if (obj[key][0] > 0) temp += 1;
          for (let j = 1; j < obj[key].length; j += 1) {
            if (obj[key][j] - obj[key][j - 1] > 1) temp += 1;
          }
          if (obj[key][obj[key].length - 1] < n - 1) temp += 1;
        idx = Math.min(idx, temp);
      }

      console.log(uq ? idx : 1);
      i += 2;
    }

}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const p="local"===process.argv[2],f=t=>{if(p){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(" ").map((t=>parseFloat(t)))}function c(){return a().split("")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t]=i.default.nextNumbers(),e=i.default.nextNumbers(),r=[],n=Array(t+1).fill(0),o=e[0],s=!0;for(let r=0;r<t;++r)e[r]!=o&&(s=!1);r.push(e[0]);for(let n=1;n<t;++n)r[n]!=r[n-1]&&r.push(e[n]);for(let e=0;e<t;++e)n[r[e]]++;if(s)return void i.default.puts(0);if(1==n[r[0]])return void i.default.puts(1);let u=t,l=r.length;for(let e=0;e<t;++e){let t=n[r[e]]+1;r[0]==r[e]&&t--,r[l-1]==r[e]&&t--,u=[u,t].min()}i.default.puts(u)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let b: number[] = []
//
//   let cnt = Array(n + 1).fill(0)
//
//   let x = a[0]
//
//   let allEq = true
//
//   for (let i = 0; i < n; ++i) {
//     if (a[i] != x) {
//       allEq = false
//     }
//   }
//
//   b.push(a[0])
//
//   for (let i = 1; i < n; ++i) {
//     if (b[i] != b[i - 1]) {
//       b.push(a[i])
//     }
//   }
//
//   for (let i = 0; i < n; ++i) {
//     cnt[b[i]]++
//   }
//
//   if (allEq) {
//     io.puts(0)
//     return
//   }
//
//   if (cnt[b[0]] == 1) {
//     io.puts(1)
//     return
//   }
//
//   let best = n
//
//   let m = b.length
//
//   for (let i = 0; i < n; ++i) {
//     let candidate = cnt[b[i]] + 1
//
//     if (b[0] == b[i]) {
//       candidate--
//     }
//
//     if (b[m - 1] == b[i]) {
//       candidate--
//     }
//
//     best = [best, candidate].min()
//   }
//
//   io.puts(best)
// }
//
// io.runEachTest(main)
// // io.runMain(main)


const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const calc = (n, x, a)=>{
    let count = 0;

    let min = Infinity;
    let max = -1;
    let minPos = -1;
    let maxPos = -1;

    for (let i = 0; i < n; i++) {
        if (a[i] < min) {
            min = a[i];
            minPos = i;
        }
        if (a[i] > max) {
            max = a[i];
            maxPos = i;
        }
        if (i === 0) continue;
        count += Math.abs(a[i] - a[i - 1]);
    }

    // console.log('DEBUG count', count);

    let minLabel = undefined;

    let mins = [Infinity, Infinity, Infinity];

    if (min > 1) {
        if (minPos === 0) {
            count += min - 1;
            minLabel = 'left';
        } else if (minPos === n - 1) {
            count += min - 1;
            minLabel = 'right';
        } else {
            mins[1] = 2 * (min - 1);
            mins[0] = a[0] - 1;
            mins[2] = a[n - 1] - 1;
            minLabel = 'mid';
        }
    }

    // console.log('DEBUG count', count);

    let maxLabel = undefined;
    let maxs = [Infinity, Infinity, Infinity];

    if (max < x) {
        if (maxPos === 0) {
            count += x - max;
            maxLabel = 'left';
        } else if (maxPos === n - 1) {
            count += x - max;
            maxLabel = 'right';
        } else {
            maxLabel = 'mid';
            maxs[1] = 2 * (x - max);
            maxs[0] = x - a[0];
            maxs[2] = x - a[n - 1];

            // if (leftPlacement < maxRes && minLabel !== 'left') {
            //     maxRes = leftPlacement;
            // }
            // if (rightPlacement < maxRes && minLabel !== 'right') {
            //     maxRes = rightPlacement;
            // }
            // count += maxRes;
        }
    }

    if (minLabel !== 'mid' && maxLabel !== 'mid') {
        return count;
    } else if (minLabel === 'mid' && maxLabel !== 'mid') {
        let minMin = mins[1];
        if (maxLabel !== 'left' && mins[0] < minMin) {
            minMin = mins[0];
        }
        if (maxLabel !== 'right' && mins[2] < minMin) {
            minMin = mins[2];
        }
        count += minMin;
    } else if (maxLabel === 'mid' && minLabel !== 'mid') {
        let maxMin = maxs[1];
        if (minLabel !== 'left' && maxs[0] < maxMin) {
            maxMin = maxs[0];
        }
        if (minLabel !== 'right' && maxs[2] < maxMin) {
            maxMin = maxs[2];
        }
        count += maxMin;
    } else {
        let minRes = Infinity;

        for (let i = 0; i < 3; i++) {
            for (let j = 0; j < 3; j++) {
                if (i === j && i !== 1) continue;
                minRes = Math.min(minRes, mins[i] + maxs[j]);
            }
        }
        count += minRes;
    }

    // console.log('DEBUG count', count);

    return count;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let [n, x] = ra();
        let a = ra();
        console.log(`${calc(n, x, a)}`);
    }
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, x, a) {
  if (n === 1) {
    console.log(Math.max(x, a[0]) - 1);
    return;
  }
  let min = 1,
      max = x,
      sum = 0;
  for (let i = 1; i < n; i++) {
    sum += Math.abs(a[i] - a[i - 1]);
  }
  let res = Infinity;
  for (let num of [min, max]) {
    res = Infinity;
    let t = 0;
    for (let i = 0; i <= a.length; i++) {
      let ans = 0;
      if (i === 0) {
        ans = sum + Math.abs(num - a[0]);
      } else if (i === a.length) {
        ans = sum + Math.abs(num - a[a.length - 1]);
      } else {
        ans = sum - Math.abs(a[i] - a[i - 1]) + Math.abs(a[i] - num) + Math.abs(a[i - 1] - num);
      }
      if (ans < res) {
        res = ans;
        t = i;
      }
    }
    a.splice(t, 0, num);
    sum = res;
  }
  console.log(res);
}

async function main(read) {
  let t = Number(await read());
  while (t--) {
    const [n, x] = (await read()).split(' ').map(Number);
    const a = (await read()).split(' ').map(Number);
    solve(n, x, a);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

const fs = require("fs");

const input = fs.readFileSync(0, "utf8").trim().split("\n");

const testCases = [];
let T;

function parseInput() {
  T = parseInt(input[0]);
  let index = 0;

  for (let i = 0; i < T; i++) {
    index++;
    const [n, x] = input[index].split(" ").map((item) => parseInt(item));
    index++;
    const a = input[index].split(" ").map((item) => parseInt(item));
    const testCase = {
      n,
      x,
      a,
    };

    testCases.push(testCase);
  }
}

function solution(testCase, index) {
  const { n, x, a } = testCase;
  // console.log(n, x, a);

  let result = a.reduce(
    (acc, val, i) => (i == 0 ? 0 : acc + Math.abs(val - a[i - 1])),
    0
  );

  // console.log("sum", result);

  const mini = Math.min(...a);
  const maxi = Math.max(...a);
  // console.log(mini, maxi);

  const miniRange = mini > 1 ? [1, Math.min(x, mini - 1)] : undefined;
  const maxiRange = maxi < x ? [maxi + 1, x] : undefined;

  // console.log(miniRange, maxiRange);

  if (miniRange) {
    const possibleSums = [];
    possibleSums.push(
      Math.max(Math.abs(a[0] - miniRange[0]), Math.abs(a[0] - miniRange[1]))
    );
    possibleSums.push(
      Math.max(
        Math.abs(a[n - 1] - miniRange[0]),
        Math.abs(a[n - 1] - miniRange[1])
      )
    );
    possibleSums.push((mini - miniRange[0]) * 2);
    // console.log("mini possibleSums", possibleSums);
    result += Math.min(...possibleSums);
  }

  if (maxiRange) {
    const possibleSums = [];
    possibleSums.push(
      Math.max(Math.abs(a[0] - maxiRange[0]), Math.abs(a[0] - maxiRange[1]))
    );
    possibleSums.push(
      Math.max(
        Math.abs(a[n - 1] - maxiRange[0]),
        Math.abs(a[n - 1] - maxiRange[1])
      )
    );
    possibleSums.push((maxiRange[1] - maxi) * 2);
    // console.log("maxi possibleSums", possibleSums);
    result += Math.min(...possibleSums);
  }

  console.log(result);
}

parseInput();

testCases.forEach(solution);

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, insert] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, insert, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, insert, arr) {
    let min = 1
    let max = insert
    let ans = 0
    let pmin = Math.abs(min - arr[0])
    let pmax = Math.abs(max - arr[0])
    let vmin = Infinity
    let vmax = -Infinity
    for (let i = 0; i < arr.length; i++) {
        const x = arr[i]
        vmin = Math.min(vmin, x)
        vmax = Math.max(vmax, x)
        // after i
        const now = i + 1 < n ? Math.abs(x - arr[i + 1]) : 0
        ans += now
        const cmin = Math.abs(min - x) + (i + 1 < n ? Math.abs(min - arr[i + 1]) : 0)
        const cmax = Math.abs(max - x) + (i + 1 < n ? Math.abs(max - arr[i + 1]) : 0)
        pmin = Math.min(pmin, cmin - now)
        pmax = Math.min(pmax, cmax - now)
    }
    // console.log(ans, pmin, pmax)
    if (max > vmax) ans += pmax
    if (min < vmin) ans += pmin
    return ans
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, insert] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, insert, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, insert, arr) {
    let min = 1
    let max = insert
    let ans = 0
    let pmin = Math.abs(min - arr[0])
    let pmax = Math.abs(max - arr[0])
    let vmin = Infinity
    let vmax = -Infinity
    for (let i = 0; i < arr.length; i++) {
        const x = arr[i]
        vmin = Math.min(vmin, x)
        vmax = Math.max(vmax, x)
        // after i
        const now = i + 1 < n ? Math.abs(x - arr[i + 1]) : 0
        ans += now
        const cmin = Math.abs(min - x) + (i + 1 < n ? Math.abs(min - arr[i + 1]) : 0)
        const cmax = Math.abs(max - x) + (i + 1 < n ? Math.abs(max - arr[i + 1]) : 0)
        pmin = Math.min(pmin, cmin - now)
        pmax = Math.min(pmax, cmax - now)
    }
    // console.log(ans, pmin, pmax)
    if (max <= vmax) {
        return ans + pmin
    } else if (min >= vmin) {
        return ans + pmax
    } else {
        return ans
    }
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, insert] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, insert, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, insert, arr) {
    let min = 1
    let max = insert
    let ans = 0
    let pmin = Math.abs(min - arr[0])
    let pmax = Math.abs(max - arr[0])
    for (let i = 0; i < arr.length; i++) {
        // after i
        const x = arr[i]
        const now = i + 1 < n ? Math.abs(x - arr[i + 1]) : 0
        ans += now
        const cmin = Math.abs(min - x) + (i + 1 < n ? Math.abs(min - arr[i + 1]) : 0)
        const cmax = Math.abs(max - x) + (i + 1 < n ? Math.abs(max - arr[i + 1]) : 0)
        pmin = Math.min(pmin, cmin - now)
        pmax = Math.min(pmax, cmax - now)
    // console.log(ans, pmin, pmax)
    }
    return n === 1 ? ans + pmin : ans + pmin + pmax
}

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const calc = (n, x, a)=>{
    let count = 0;

    let min = Infinity;
    let max = -1;
    let minPos = -1;
    let maxPos = -1;

    for (let i = 0; i < n; i++) {
        if (a[i] < min) {
            min = a[i];
            minPos = i;
        }
        if (a[i] > max) {
            max = a[i];
            maxPos = i;
        }
        if (i === 0) continue;
        count += Math.abs(a[i] - a[i - 1]);
    }

    // console.log('DEBUG count', count);

    let minLabel = undefined;

    if (min > 1) {
        if (minPos === 0) {
            count += min - 1;
            minLabel = 'left';
        } else if (minPos === n - 1) {
            count += min - 1;
            minLabel = 'right';
        } else {
            count += 2 * (min - 1);
            minLabel = 'mid';
        }
    }

    // console.log('DEBUG count', count);

    if (max < x) {
        if (maxPos === 0) {
            count += x - max;
        } else if (maxPos === n - 1) {
            count += x - max;
        } else {
            let maxRes = 2 * (x - max);
            let leftPlacement = x - a[0];
            let rightPlacement = x - a[n - 1];

            if (leftPlacement < maxRes && minLabel !== 'left') {
                maxRes = leftPlacement;
            }
            if (rightPlacement < maxRes && minLabel !== 'right') {
                maxRes = rightPlacement;
            }
            count += maxRes;
        }
    }

    // console.log('DEBUG count', count);

    return count;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let [n, x] = ra();
        let a = ra();
        console.log(`${calc(n, x, a)}`);
    }
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, x, a) {
  if (n === 1) {
    console.log(Math.max(x, a[0]) - 1);
    return;
  }
  let min = 1,
      max = x,
      sum = 0;
  for (let i = 1; i < n; i++) {
    sum += Math.abs(a[i] - a[i - 1]);
  }
  let res = Infinity;
  for (let num of [min, max]) {
    res = Infinity;
    for (let i = 0; i <= n; i++) {
      if (i === 0) {
        res = Math.min(res, sum + Math.abs(num - a[0]));
      } else if (i === n) {
        res = Math.min(res, sum + Math.abs(num - a[n - 1]));
      } else {
        res = Math.min(res, sum - Math.abs(a[i] - a[i - 1]) + Math.abs(a[i] - num) + Math.abs(a[i - 1] - num));
      }
    }
    sum = res;
  }
  console.log(res);
}

async function main(read) {
  let t = Number(await read());
  while (t--) {
    const [n, x] = (await read()).split(' ').map(Number);
    const a = (await read()).split(' ').map(Number);
    solve(n, x, a);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();