You are given a string $$$t$$$ consisting of $$$n$$$ lowercase Latin letters and an integer number $$$k$$$.Let's define a substring of some string $$$s$$$ with indices from $$$l$$$ to $$$r$$$ as $$$s[l \dots r]$$$.Your task is to construct such string $$$s$$$ of minimum possible length that there are exactly $$$k$$$ positions $$$i$$$ such that $$$s[i \dots i + n - 1] = t$$$. In other words, your task is to construct such string $$$s$$$ of minimum possible length that there are exactly $$$k$$$ substrings of $$$s$$$ equal to $$$t$$$.It is guaranteed that the answer is always unique.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 50$$$) — the length of the string $$$t$$$ and the number of substrings. The second line of the input contains the string $$$t$$$ consisting of exactly $$$n$$$ lowercase Latin letters.

Print such string $$$s$$$ of minimum possible length that there are exactly $$$k$$$ substrings of $$$s$$$ equal to $$$t$$$. It is guaranteed that the answer is always unique.

function main() {
  const is = new Scanner();
  const [n, k] = is.nextArray(Number);
  const word = is.nextLine();
  const auxRev = word.slice();
  let characters = 0;
  for (let i = 1, j = word.length - 1; i < n && j > 0; i += 1, j -= 1) {
    if (word.slice(0, i) === auxRev.slice(j))
      characters = i;
  }
  const aux = word.slice(characters);
  let answer = word;
  for (let i = 1; i < k; i += 1)
    answer += aux;
  console.log(answer);
}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = -1;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    this.index += 1;
    return this.lines[this.index].trim();
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn = String) {
    const array = this.nextLine().split(' ');
    if (fn !== String)
      array.forEach((item, index, arr) => { arr[index] = fn(item); } );
    return array;
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

'use strict';

var newLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

var amount = newLine[1];
var word = readline();

var getWordPart = function getWordPart(mode, word, amount) {

  if (word.length / 2 >= amount - 0.5) {

    var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);
    return part;
  }

  return false;
};

var getMaxAmount = function getMaxAmount(word) {

  var maxAmount = 0;

  for (var counter = 0; counter < word.length; counter++) {
    var beginPart = getWordPart('begin', word, counter + 1);
    var endPart = getWordPart('end', word, counter + 1);

    if (beginPart && beginPart === endPart) {
      if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {
        return -(counter + 1);
      }
      maxAmount = counter + 1;
    }
  }

  // console.log(maxAmount)
  return maxAmount;
};

var isSameSymbols = function isSameSymbols(word, letter) {

  for (var i = 0; i < word.length; i++) {

    if (letter !== word[i]) {
      return false;
    }
  }

  // console.log('SAME')
  return true;
};

var replaceParts = function replaceParts(word, part, symbol) {

  var wordLength = word.length;

  for (var i = 0; i < wordLength / part.length + 1; i++) {
    word = word.replace(part, symbol);
  }

  // console.log('replaceParts', part, word);
  return word;
};

var addPart = function addPart(part, amount) {
  var result = '';

  while (amount > 0) {
    result += part;
    amount--;
  }

  return result;
};

var isPalindrom = function isPalindrom(word) {

  if (word[0] === word[word.length - 1]) {
    if (word.length <= 1) return true;
    return isPalindrom(word.slice(1, word.length - 1));
  }

  return false;
};

var partLength = getMaxAmount(word);
var begin = '';
var h = partLength > 0 && word.length >= 6 && word[0] === word[word.length - 1] && !isSameSymbols(word, word[0]) && isPalindrom(word);

// console.log(partLength);
if (h) {
  begin = word[0];
  partLength = getMaxAmount(word.slice(1));
  word = word.slice(1);
}

write(begin + word + addPart(word.slice(partLength), amount - 1));

var firstLine = readline();
var n = firstLine.split(" ")[0];
var k = firstLine.split(" ")[1];
var string = readline();

print(output(string, k, n))

function output(string, k, n) {
    var p = n - 1;
    var l = 0;
    var ans = 0;
    for (var i = p - 1; i >= 0; i--) {
        if (ans === 0) {
            for (var j = i; j >= 0; j--) {
                if (string[j] === string[p]) {
                    p--;
                    l++;
                    if (j === 0) {
                        ans = l;
                    }
                } else {
                    p = n - 1;
                    l = 0;
                    break;
                }
            }
        } else {
            break;
        }
    }

    for (var i = 1; i <= k - 1; i++) {
        for (var j = l; j < n; j++) {
            string += string[j];
        }
    }
    return string;
}

var args = readline().split(' ');
var str = readline();

args = args.map((n) => parseInt(n, 10));

var len = args[0];
var repeat = args[1];

var i = 1;
var mark = 0;
while (i < len) {
    var prefix = str.substring(0, i);
    var suffix = str.substring(len - i);
    if (prefix === suffix) {
        mark = i;
    }
    i++;
}

const res = [];
const substr = str.substring(mark);

res.push(str.substring(0, mark));

for (var j = 0;j < repeat;j++) {
    res.push(substr);
}

print(res.join(''));

var a = readline().split(" ");
var n = a[1];
var str = readline();
var firstP = str.slice(1);
var secondP = str.slice(0, str.length - 1);
var i,
    bool = false;
for(i = 1; i <= str.length - 1; i++){
    if(firstP == secondP){
        bool = true;
        break;
    } else{
        firstP = firstP.slice(1);
        secondP = secondP.slice(0, secondP.length - 1);
    }
}
var mainText;
if(bool){
    mainText = str.slice(secondP.length);
} else{
    mainText = str;
}
var lastResult = str;
for(i = 1; i <= n-1; i++){
    lastResult += mainText;
}
print(lastResult);

var nk = readline();
var t = readline();

var n = nk.split(" ")[0];
var k = nk.split(" ")[1];

var equal = "";
for (var i = 0; i < t.length - 1; i ++) {
    var firstSub = t.substring(0, i + 1);
    var secondSub = t.substring(t.length - i - 1, t.length);

    if (firstSub === secondSub) {
      equal = firstSub;
    }
  }

var result = t;
for (var i = 1; i < k; i ++) {
    if (equal !== "") {
        result += t.substring(equal.length, t.length);
    } else {
        result += t;
    }
}

write(result);

function main() {
  const is = new Scanner();
  const [n, k] = is.nextArray(Number);
  const word = is.nextLine();
  let answer = word, aux;
  for (let c = 1; c < k; c += 1) {
    aux = word.slice();
    for (let i = 0, j = n - 1; i < n && j >= 0; i++, j--)
      if (word[j] === aux[i]) {
        aux = word.slice(1);
      } else {
        break;
      }
    answer += aux;
  }

  console.log(answer);
}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = -1;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    this.index += 1;
    return this.lines[this.index].trim();
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn = String) {
    const array = this.nextLine().split(' ');
    if (fn !== String)
      array.forEach((item, index, arr) => { arr[index] = fn(item); } );
    return array;
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

'use strict';

var newLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

var amount = newLine[1];
var word = readline();

var getWordPart = function getWordPart(mode, word, amount) {

  if (word.length / 2 >= amount - 0.5) {

    var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);
    return part;
  }

  return false;
};

var getMaxAmount = function getMaxAmount(word) {

  // console.log(word)

  var maxAmount = 0;

  for (var counter = 0; counter < word.length; counter++) {
    var beginPart = getWordPart('begin', word, counter + 1);
    var endPart = getWordPart('end', word, counter + 1);

    if (beginPart && beginPart === endPart) {
      if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {
        return -(counter + 1);
      }
      maxAmount = counter + 1;
    }
  }

  // console.log(maxAmount)
  return maxAmount;
};

var isSameSymbols = function isSameSymbols(word, letter) {

  for (var i = 0; i < word.length; i++) {

    if (letter !== word[i]) {
      return false;
    }
  }

  return true;
};

var replaceParts = function replaceParts(word, part, symbol) {

  for (var i = 0; i < word.length / symbol.length + 1; i++) {
    word = word.replace(part, symbol);
  }

  // console.log('replaceParts', word);
  return word;
};

var addPart = function addPart(part, amount) {
  var result = '';

  while (amount > 0) {
    result += part;
    amount--;
  }

  return result;
};

var isPalindrom = function isPalindrom(word) {

  if (word[0] === word[word.length - 1]) {
    if (word.length <= 1) return true;
    return isPalindrom(word.slice(1, word.length - 1));
  }

  return false;
};

// let partLength = 0;
// let begin = '';
// let h =
//     word.length >= 6 &&
//     word[0] === word[word.length -1] &&
//     !isSameSymbols(word, word[0]) &&
//     isPalindrom(word);

// if(h){
//   begin = word[0];
//   partLength = getMaxAmount(word.slice(1));
//   word = word.slice(1);
// } else {
//   partLength = getMaxAmount(word);
// }

var partLength = getMaxAmount(word);
var a1 = word + addPart(word.slice(partLength), amount - 1);
partLength = getMaxAmount(word.slice(1));
var a2 = word[0];
word = word.slice(1);
a2 += word + addPart(word.slice(partLength), amount - 1);

write(a1.length > a2.length ? a2 : a1);

'use strict';

var newLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

var amount = newLine[1];
var word = readline();

var getWordPart = function getWordPart(mode, word, amount) {

  if (word.length / 2 >= amount - 0.5) {

    var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);
    return part;
  }

  return false;
};

var getMaxAmount = function getMaxAmount(word) {

  // console.log(word)

  var maxAmount = 0;

  for (var counter = 0; counter < word.length; counter++) {
    var beginPart = getWordPart('begin', word, counter + 1);
    var endPart = getWordPart('end', word, counter + 1);

    if (beginPart && beginPart === endPart) {
      if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {
        return -(counter + 1);
      }
      maxAmount = counter + 1;
    }
  }

  // console.log(maxAmount)
  return maxAmount;
};

var isSameSymbols = function isSameSymbols(word, letter) {

  for (var i = 0; i < word.length; i++) {

    if (letter !== word[i]) {
      return false;
    }
  }

  return true;
};

var replaceParts = function replaceParts(word, part, symbol) {

  for (var i = 0; i < word.length / symbol.length + 1; i++) {
    word = word.replace(part, symbol);
  }

  // console.log('replaceParts', word);
  return word;
};

var addPart = function addPart(part, amount) {
  var result = '';

  while (amount > 0) {
    result += part;
    amount--;
  }

  return result;
};

var isPalindrom = function isPalindrom(word) {

  if (word[0] === word[word.length - 1]) {
    if (word.length <= 1) return true;
    return isPalindrom(word.slice(1, word.length - 1));
  }

  return false;
};

// let partLength = 0;
// let begin = '';
// let h =
//     word.length >= 6 &&
//     word[0] === word[word.length -1] &&
//     !isSameSymbols(word, word[0]) &&
//     isPalindrom(word);

// if(h){
//   begin = word[0];
//   partLength = getMaxAmount(word.slice(1));
//   word = word.slice(1);
// } else {
//   partLength = getMaxAmount(word);
// }

var partLength = getMaxAmount(word);
var a1 = word + addPart(word.slice(partLength), amount - 1);
partLength = getMaxAmount(word.slice(1));
var a2 = word[0];
word = word.slice(1);
a2 += word + addPart(word.slice(partLength), amount - 1);

write(a1.length > a2.length ? a1 : a2);

'use strict';

var newLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

var amount = newLine[1];
var word = readline();

var getWordPart = function getWordPart(mode, word, amount) {

  if (word.length / 2 >= amount - 0.5) {

    var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);
    return part;
  }

  return false;
};

var getMaxAmount = function getMaxAmount(word) {

  var maxAmount = 0;

  for (var counter = 0; counter < word.length; counter++) {
    var beginPart = getWordPart('begin', word, counter + 1);
    var endPart = getWordPart('end', word, counter + 1);

    if (beginPart && beginPart === endPart) {
      if (isSameSymbols(replaceParts(word, beginPart, '*'))) {
        return -(counter + 1);
      }
      maxAmount = counter + 1;
    }
  }

  return maxAmount;
};

var isSameSymbols = function isSameSymbols(word, letter) {

  for (var i = 0; i < word.length; i++) {

    if (letter !== word[i]) {
      return false;
    }
  }

  return true;
};

var replaceParts = function replaceParts(word, part, symbol) {

  while (word.length > word.replace(part, symbol).length) {
    word = word.replace(part, symbol);
  }

  return word;
};

var addPart = function addPart(part, amount) {
  var result = '';

  while (amount > 0) {
    result += part;
    amount--;
  }

  return result;
};

var partLength = getMaxAmount(word);
write(word + addPart(word.slice(partLength), amount - 1));

'use strict';

var newLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

var amount = newLine[1];
var word = readline();

var getWordPart = function getWordPart(mode, word, amount) {

  if (word.length / 2 >= amount - 0.5) {

    var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);
    return part;
  }

  return false;
};

var getMaxAmount = function getMaxAmount(word) {

  // console.log(word)

  var maxAmount = 0;

  for (var counter = 0; counter < word.length; counter++) {
    var beginPart = getWordPart('begin', word, counter + 1);
    var endPart = getWordPart('end', word, counter + 1);

    if (beginPart && beginPart === endPart) {
      if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {
        return -(counter + 1);
      }
      maxAmount = counter + 1;
    }
  }

  // console.log(maxAmount)
  return maxAmount;
};

var isSameSymbols = function isSameSymbols(word, letter) {

  for (var i = 0; i < word.length; i++) {

    if (letter !== word[i]) {
      return false;
    }
  }

  return true;
};

var replaceParts = function replaceParts(word, part, symbol) {

  for (var i = 0; i < word.length / symbol.length + 1; i++) {
    word = word.replace(part, symbol);
  }

  // console.log('replaceParts', word);
  return word;
};

var addPart = function addPart(part, amount) {
  var result = '';

  while (amount > 0) {
    result += part;
    amount--;
  }

  return result;
};

var isPalindrom = function isPalindrom(word) {

  if (word[0] === word[word.length - 1]) {
    if (word.length <= 1) return true;
    return isPalindrom(word.slice(1, word.length - 1));
  }

  return false;
};

var partLength = 0;
var begin = '';
var test = !isSameSymbols(word, word[0]) && word.length >= 6 && word[0] === word[word.length - 1];
if (test) {
  begin = word[0];
  partLength = getMaxAmount(word.slice(1));
  word = word.slice(1);
} else {
  partLength = getMaxAmount(word);
}

write(begin + word + addPart(word.slice(partLength), amount - 1));

'use strict';

var newLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

var amount = newLine[1];
var word = readline();

var getWordPart = function getWordPart(mode, word, amount) {

  if (word.length / 2 >= amount - 0.5) {

    var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);
    return part;
  }

  return false;
};

var getMaxAmount = function getMaxAmount(word) {

  var maxAmount = 0;

  for (var counter = 0; counter < word.length; counter++) {
    var beginPart = getWordPart('begin', word, counter + 1);
    var endPart = getWordPart('end', word, counter + 1);

    if (beginPart && beginPart === endPart) {
      if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {
        return -(counter + 1);
      }
      maxAmount = counter + 1;
    }
  }

  return maxAmount;
};

var isSameSymbols = function isSameSymbols(word, letter) {

  for (var i = 0; i < word.length; i++) {

    if (letter !== word[i]) {
      return false;
    }
  }

  return true;
};

var replaceParts = function replaceParts(word, part, symbol) {

  while (word.length > word.replace(part, symbol).length) {
    word = word.replace(part, symbol);
  }

  return word;
};

var addPart = function addPart(part, amount) {
  var result = '';

  while (amount > 0) {
    result += part;
    amount--;
  }

  return result;
};

var isPalindrom = function isPalindrom(word) {

  if (word[0] === word[word.length - 1]) {
    if (word.length <= 1) return true;
    return isPalindrom(word.slice(1, word.length - 1));
  }

  return false;
};

var partLength = getMaxAmount(word.length >= 5 && isPalindrom(word) ? word.slice(1) : word);
write(word + addPart(word.slice(partLength), amount - 1));

'use strict';

var newLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

var amount = newLine[1];
var word = readline();

var getWordPart = function getWordPart(mode, word, amount) {

  if (word.length / 2 >= amount - 0.5) {

    var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);
    return part;
  }

  return false;
};

var getMaxAmount = function getMaxAmount(word) {

  var maxAmount = 0;

  for (var counter = 0; counter < word.length; counter++) {
    var beginPart = getWordPart('begin', word, counter + 1);
    var endPart = getWordPart('end', word, counter + 1);

    if (beginPart && beginPart === endPart) {
      if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {
        return -(counter + 1);
      }
      maxAmount = counter + 1;
    }
  }

  return maxAmount;
};

var isSameSymbols = function isSameSymbols(word, letter) {

  for (var i = 0; i < word.length; i++) {

    if (letter !== word[i]) {
      return false;
    }
  }

  return true;
};

var replaceParts = function replaceParts(word, part, symbol) {

  while (word.length > word.replace(part, symbol).length) {
    word = word.replace(part, symbol);
  }

  return word;
};

var addPart = function addPart(part, amount) {
  var result = '';

  while (amount > 0) {
    result += part;
    amount--;
  }

  return result;
};

var isPalindrom = function isPalindrom(word) {

  if (word[0] === word[word.length - 1]) {
    if (word.length <= 1) return true;
    return isPalindrom(word.slice(1, word.length - 1));
  }

  return false;
};

var partLength = getMaxAmount(isPalindrom(word) ? word.slice(1) : word);
write(word + addPart(word.slice(partLength), amount - 1));

'use strict';

var newLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

var amount = newLine[1];
var word = readline();

var getWordPart = function getWordPart(mode, word, amount) {

  if (word.length / 2 >= amount - 0.5) {

    var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);
    return part;
  }

  return false;
};

var getMaxAmount = function getMaxAmount(word) {

  var maxAmount = 0;

  for (var counter = 0; counter < word.length; counter++) {
    if (getWordPart('begin', word, counter + 1) && getWordPart('begin', word, counter + 1) && getWordPart('begin', word, counter + 1) === getWordPart('end', word, counter + 1)) {
      maxAmount = counter + 1;
    }
  }

  return maxAmount;
};

var isSameLetters = function isSameLetters(word) {
  var letter = word[0];

  for (var i = 0; i < word.length; i++) {

    if (letter !== word[i]) {
      return false;
    }
  }

  return true;
};

var a = function a(part, amount) {
  var result = '';

  for (var i = 0; i < amount; i++) {
    result += part;
  }

  return result;
};

var replaceParts = function replaceParts(word, part) {

  while (word.length > word.replace(part, 'a').length) {
    word = word.replace(part, 'a');
  }

  return word;
};

if (isSameLetters(word)) {
  write(word + a(word[0], amount - 1));
} else {
  var partLength = getMaxAmount(word);

  if (isSameLetters(replaceParts(word, word.slice(-partLength)))) {
    write(word + a(word.slice(-partLength), amount - 1));
  } else {
    write(word + a(word.slice(partLength), amount - 1));
  }
}

'use strict';

var newLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

var amount = newLine[1];
var word = readline();

var getWordPart = function getWordPart(mode, word, amount) {

  if (word.length / 2 >= amount - 0.5) {

    var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);
    return part;
  }

  return false;
};

var getMaxAmount = function getMaxAmount(word) {

  // console.log(word)

  var maxAmount = 0;

  for (var counter = 0; counter < word.length; counter++) {
    var beginPart = getWordPart('begin', word, counter + 1);
    var endPart = getWordPart('end', word, counter + 1);

    if (beginPart && beginPart === endPart) {
      if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {
        return -(counter + 1);
      }
      maxAmount = counter + 1;
    }
  }

  // console.log(maxAmount)
  return maxAmount;
};

var isSameSymbols = function isSameSymbols(word, letter) {

  for (var i = 0; i < word.length; i++) {

    if (letter !== word[i]) {
      return false;
    }
  }

  return true;
};

var replaceParts = function replaceParts(word, part, symbol) {

  for (var i = 0; i < word.length / symbol.length + 1; i++) {
    word = word.replace(part, symbol);
  }

  // console.log('replaceParts', word);
  return word;
};

var addPart = function addPart(part, amount) {
  var result = '';

  while (amount > 0) {
    result += part;
    amount--;
  }

  return result;
};

var isPalindrom = function isPalindrom(word) {

  if (word[0] === word[word.length - 1]) {
    if (word.length <= 1) return true;
    return isPalindrom(word.slice(1, word.length - 1));
  }

  return false;
};

var partLength = 0;
if (!isSameSymbols(word, word[0]) && word.length >= 6 && word[0] === word[word.length - 1]) {
  partLength = getMaxAmount(word.slice(1));
} else {
  partLength = getMaxAmount(word);
}

write(word + addPart(word.slice(partLength), amount - 1));

'use strict';

var newLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

var amount = newLine[1];
var word = readline();

var getWordPart = function getWordPart(mode, word, amount) {

  if (word.length / 2 >= amount - 0.5) {

    var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);
    return part;
  }

  return false;
};

var getMaxAmount = function getMaxAmount(word) {

  var maxAmount = 0;

  for (var counter = 0; counter < word.length; counter++) {
    var beginPart = getWordPart('begin', word, counter + 1);
    var endPart = getWordPart('end', word, counter + 1);

    if (beginPart && beginPart === endPart) {
      if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {
        return -(counter + 1);
      }
      maxAmount = counter + 1;
    }
  }

  // console.log(maxAmount)
  return maxAmount;
};

var isSameSymbols = function isSameSymbols(word, letter) {

  for (var i = 0; i < word.length; i++) {

    if (letter !== word[i]) {
      return false;
    }
  }

  // console.log('SAME')
  return true;
};

var replaceParts = function replaceParts(word, part, symbol) {

  for (var i = 0; i < word.length / part.length + 1; i++) {
    word = word.replace(part, symbol);
  }

  // console.log('replaceParts', part, word);
  return word;
};

var addPart = function addPart(part, amount) {
  var result = '';

  while (amount > 0) {
    result += part;
    amount--;
  }

  return result;
};

var isPalindrom = function isPalindrom(word) {

  if (word[0] === word[word.length - 1]) {
    if (word.length <= 1) return true;
    return isPalindrom(word.slice(1, word.length - 1));
  }

  return false;
};

var partLength = getMaxAmount(word);
var begin = '';
var h = partLength > 0 && word.length >= 6 && word[0] === word[word.length - 1] && !isSameSymbols(word, word[0]) && isPalindrom(word);

// console.log(partLength);
if (h) {
  begin = word[0];
  partLength = getMaxAmount(word.slice(1));
  word = word.slice(1);
}

write(begin + word + addPart(word.slice(partLength), amount - 1));

'use strict';

var newLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

var amount = newLine[1];
var word = readline();

var getWordPart = function getWordPart(mode, word, amount) {

  if (word.length / 2 >= amount - 0.5) {

    var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);
    return part;
  }

  return false;
};

var getMaxAmount = function getMaxAmount(word) {

  // console.log(word)

  var maxAmount = 0;

  for (var counter = 0; counter < word.length; counter++) {
    var beginPart = getWordPart('begin', word, counter + 1);
    var endPart = getWordPart('end', word, counter + 1);

    if (beginPart && beginPart === endPart) {
      if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {
        return -(counter + 1);
      }
      maxAmount = counter + 1;
    }
  }

  // console.log(maxAmount)
  return maxAmount;
};

var isSameSymbols = function isSameSymbols(word, letter) {

  for (var i = 0; i < word.length; i++) {

    if (letter !== word[i]) {
      return false;
    }
  }

  return true;
};

var replaceParts = function replaceParts(word, part, symbol) {

  for (var i = 0; i < word.length / symbol.length + 1; i++) {
    word = word.replace(part, symbol);
  }

  // console.log('replaceParts', word);
  return word;
};

var addPart = function addPart(part, amount) {
  var result = '';

  while (amount > 0) {
    result += part;
    amount--;
  }

  return result;
};

var isPalindrom = function isPalindrom(word) {

  if (word[0] === word[word.length - 1]) {
    if (word.length <= 1) return true;
    return isPalindrom(word.slice(1, word.length - 1));
  }

  return false;
};

var partLength = 0;
var begin = '';
var h = word.length >= 6 && word[0] === word[word.length - 1] && !isSameSymbols(word, word[0]) && isPalindrom(word);

if (h) {
  begin = word[0];
  partLength = getMaxAmount(word.slice(1));
  word = word.slice(1);
} else {
  partLength = getMaxAmount(word);
}

write(begin + word + addPart(word.slice(partLength), amount - 1));

'use strict';

var newLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

var amount = newLine[1];
var word = readline();

var getWordPart = function getWordPart(mode, word, amount) {

  if (word.length / 2 >= amount - 0.5) {

    var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);
    return part;
  }

  return false;
};

var getMaxAmount = function getMaxAmount(word) {

  var maxAmount = 0;

  for (var counter = 0; counter < word.length; counter++) {
    if (getWordPart('begin', word, counter + 1) && getWordPart('begin', word, counter + 1) && getWordPart('begin', word, counter + 1) === getWordPart('end', word, counter + 1)) {
      maxAmount = counter + 1;
    }
  }

  return maxAmount;
};

var isSameLetters = function isSameLetters(word) {
  var letter = word[0];

  for (var i = 0; i < word.length; i++) {

    if (letter !== word[i]) {
      return false;
    }
  }

  return true;
};

var a = function a(part, amount) {
  var result = '';

  for (var i = 0; i < amount; i++) {
    result += part;
  }

  return result;
};

if (isSameLetters(word)) {
  write(word + a(word[0], amount - 1));
} else {
  var partLength = getMaxAmount(word);
  write(word + a(word.slice(partLength), amount - 1));
}

var firstLine = readline();
var n = firstLine.split(" ")[0];
var k = firstLine.split(" ")[1];
var string = readline();

print(output(string, k, n))

function output(string, k, n) {
    var p = n - 1;
    var l = 0;
    for (var i = p - 1; i >= 0; i--) {
        if (string[p] === string[i]) {
            p--;
            l++;
        } else if (string[n-1] === string[i] && string[p+1] === string[i+1]) {
            p = n - 2;
            l = 1;
        } else {
            p = n - 1;
            l = 0;
        }
    }

    for (var i = 1; i <= k - 1; i++) {
        for (var j = l; j < n; j++) {
            string += string[j];
        }
    }
    return string;
}

var firstLine = readline();
var n = firstLine.split(" ")[0];
var k = firstLine.split(" ")[1];
var string = readline();

print(output(string, k))

function output(string, k) {
    var p = 0;
    var t = 0;
    for (var i = 1; i < string.length; i++) {
        if (string[p] !== string[i+p]) {
            p = 0;
            t = i;
        } else {
            p++;
            break;
        }
    }
    var u = string.length;
    if (t + 1 === u) {
        t = 0;
    }
    for (var o = 0; o < k - 1; o++) {
        for (var i = t; i < u; i++) {
            string = string + string[i];
        }
    }
    return string;
}

var firstLine = readline();
var n = firstLine.split(" ")[0];
var k = firstLine.split(" ")[1];
var string = readline();

print(output(string, k))

function output(string, k) {
    var p = 0;
    var t = 0;
    for (var i = 1; i < string.length; i++) {
        print (p, i, string[p], string[i])
        if (string[p] !== string[i]) {
            print (string[p-1], string[i])
            if (string[p-1] === string[i]) {
                p = 1;
                t = i - 1;
            } else {
                p = 0;
                t = i;
            }
        } else {
            p++;
        }
    }
    print(t)
    var u = string.length;
    for (var o = 0; o < k - 1; o++) {
        for (var i = u-t-1; i < u; i++) {
            string = string + string[i];
        }
    }
    return string;
}

var firstLine = readline();
var n = firstLine.split(" ")[0];
var k = firstLine.split(" ")[1];
var string = readline();

print(output(string, k))

function output(string, k) {
    var p = 0;
    var t = 0;
    for (var i = 1; i < string.length; i++) {
        if (string[p] !== string[i]) {
            if (string[p-1] === string[i]) {
                p = 1;
                t = i - 1;
            } else {
                p = 0;
                t = i;
            }
        } else {
            p++;
        }
    }
    var u = string.length;
    for (var o = 0; o < k - 1; o++) {
        for (var i = u-t-1; i < u; i++) {
            string = string + string[i];
        }
    }
    return string;
}

var firstLine = readline();
var n = firstLine.split(" ")[0];
var k = firstLine.split(" ")[1];
var string = readline();

print(output(string, k))

function output(string, k) {
    var p = 0;
    var t = 0;
    for (var i = 1; i < string.length; i++) {

        if (string[p] !== string[i+p]) {
            p = 0;
            t = i;
        } else {
            p++;
        }
    }
    var u = string.length;
    if (t + 1 === u) {
        t = 0;
    }
    for (var o = 0; o < k - 1; o++) {
        for (var i = t; i < u; i++) {
            string = string + string[i];
        }
    }
    return string;
}

var firstLine = readline();
var n = firstLine.split(" ")[0];
var k = firstLine.split(" ")[1];
var string = readline();

print(output(string, k))

function output(string, k) {
    var p = 0;
    var t = 0;
    for (var i = 1; i < string.length; i++) {
        if (string[p] !== string[i]) {
            p = 0;
            t = i;
        } else {
            p++;
        }
    }
    var u = string.length;
    for (var o = 0; o < k - 1; o++) {
        for (var i = u-t-1; i < u; i++) {
            string = string + string[i];
        }
    }
    return string;
}

var args = readline().split(' ');
var str = readline();

args = args.map((n) => parseInt(n, 10));

var len = args[0];
var repeat = args[1];

var i = 0;
var mid = parseInt(len / 2);
while (i < mid) {
    if (str[i] !== str[len - i - 1]) {
        break;
    }
    i++;
}

const res = []
const substr = str.substring(i);

res.push(str.substring(0, i));
for (var j = 0;j < repeat;j++) {
    res.push(substr);
}

print(res.join(''));

var a = readline().split("");
var n = a[1];
var str = readline();
var firstP = str.slice(1);
var secondP = str.slice(0, str.length - 1);
var i,
    bool = false;
for(i = 1; i <= str.length - 1; i++){
    if(firstP == secondP){
        bool = true;
        break;
    } else{
        firstP = firstP.slice(1);
        secondP = secondP.slice(0, secondP.length - 1);
    }
}
var mainText;
if(bool){
    mainText = str.slice(secondP.length);
} else{
    mainText = str;
}
var lastResult = str;
for(i = 1; i <= n-1; i++){
    lastResult += mainText;
}
print(lastResult);

function myFunc(t, n){

    var firstP = t.slice(1);
    var secondP = t.slice(0, t.length - 1);
    var i,
        bool = false;
    for(i = 1; i <= t.length - 1; i++){
        if(firstP == secondP){
            bool = true;
            break;
        } else{
            firstP = firstP.slice(1);
            secondP = secondP.slice(0, secondP.length - 1);
        }
    }
    var mainText;
    if(bool){
        mainText = t.slice(secondP.length);
    } else{
        mainText = t;
    }
    var lastResult = t;
    for(i = 1; i <= n-1; i++){
        lastResult += mainText;
    }
    return lastResult;
}
myFunc(readline());

var nk = readline();
var t = readline();

var n = nk.split(" ")[0];
var k = nk.split(" ")[1];

var equal = "";
for (var i = 0; i < Math.floor(t.length / 2); i ++) {
  var firstSub = t.substring(0, i + 1);
  var secondSub = t.substring(t.length - i - 1, t.length);
  if (firstSub === secondSub) {
    equal = firstSub;
  } else {
    break;
  }
}

var result = t;
for (var i = 1; i < k; i ++) {
    if (equal !== "") {
        result += t.substring(equal.length, t.length);
    } else {
        result += t;
    }
}

write(result);


You had $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ arranged in a circle. For each pair of neighboring numbers ($$$a_1$$$ and $$$a_2$$$, $$$a_2$$$ and $$$a_3$$$, ..., $$$a_{n - 1}$$$ and $$$a_n$$$, and $$$a_n$$$ and $$$a_1$$$), you wrote down: are the numbers in the pair equal or not.Unfortunately, you've lost a piece of paper with the array $$$a$$$. Moreover, you are afraid that even information about equality of neighboring elements may be inconsistent. So, you are wondering: is there any array $$$a$$$ which is consistent with information you have about equality or non-equality of corresponding pairs?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains a non-empty string $$$s$$$ consisting of characters E and/or N. The length of $$$s$$$ is equal to the size of array $$$n$$$ and $$$2 \le n \le 50$$$. For each $$$i$$$ from $$$1$$$ to $$$n$$$:    if $$$s_i =$$$ E then $$$a_i$$$ is equal to $$$a_{i + 1}$$$ ($$$a_n = a_1$$$ for $$$i = n$$$);  if $$$s_i =$$$ N then $$$a_i$$$ is not equal to $$$a_{i + 1}$$$ ($$$a_n \neq a_1$$$ for $$$i = n$$$).

For each test case, print YES if it's possible to choose array $$$a$$$ that are consistent with information from $$$s$$$ you know. Otherwise, print NO. It can be proved, that if there exists some array $$$a$$$, then there exists an array $$$a$$$ of positive integers with values less or equal to $$$10^9$$$.

NoteIn the first test case, you can choose, for example, $$$a_1 = a_2 = a_3 = 5$$$.In the second test case, there is no array $$$a$$$, since, according to $$$s_1$$$, $$$a_1$$$ is equal to $$$a_2$$$, but, according to $$$s_2$$$, $$$a_2$$$ is not equal to $$$a_1$$$.In the third test case, you can, for example, choose array $$$a = [20, 20, 4, 50, 50, 50, 20]$$$.In the fourth test case, you can, for example, choose $$$a = [1, 3, 3, 7]$$$.

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')
}

// 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()

// 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");
    }

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

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");
    }
  }

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");
}