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

    B();
});

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 > 0){
        t--;
        let n = pi(readline());
        let x = n;
        let res = [4*n];
        let num = 4*n;
        n -= 1;
        let i = 3;
        let f = 2;
        while(n > 0){
                num -= 2;
                let flag = false;
                for(let j = res.length-1; j >= 0; j--){
                    if(res[j] % num === 0){
                        flag = true;
                        break;
                    }
                }
                if(!flag){
                    res.push(num);
                    n--;
                }
        }

        console.log(res.join(' '));
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [a,b] = ti(readline().split(' '));
        let s = readline().split('');
        //console.log(s.length);
        let x = [];
        let i = 0;
        while(i < s.length && s[i] !== '1'){
            i++;
        }

        while(i < s.length){
            if(s[i] === '1')
                x.push(a);
            while(i < s.length && s[i] === '1'){
                i++;
            }

            if(i < s.length && s[i] === '0'){
                x.push(s[i]);
            }
            i++;
        }

        i = 0;
        let sum = x.length !== 0 ? a : 0;
        while(i < x.length){
            if(pi(x[i]) === a){
                let count = 0;
                i++;
                while(i < x.length && pi(x[i]) === 0){
                    count += b;
                    i++;
                }

                if(i < x.length){
                    sum = Math.min(sum+a, sum+count);
                }
            }
        }

        console.log(sum);
    }
}

let input = ''

process.stdin.on('data', (x) => input += x)

process.stdin.on('end', () => {
  const lines = input.trim().split('\n')
  let curLine = 0
  const T = parseInt(lines[curLine++])
  for (let t = 0; t < T; t++) {
    const [a, b] = parseIntArray(lines[curLine++])
    const spaces = []
    let count = 0
    let last = '0'
    let length = 0
    lines[curLine++].split('').forEach((c) => {
      if (c === '1') {
        if (length > 0 && count > 0) {
          spaces.push(length)
        }
        if (last === '0') {
          count++
        }
        length = 0
        last = '1'
      } else {
        length++
        last = '0'
      }
    })
    let ans = 0
    spaces.sort((x, y) => x - y).forEach((len) => {
      if (b * len < a) {
        ans += b * len
        count--
      }
    })

    console.log(ans + a * count)
  }
})

const parseIntArray = (line) => line.split(' ').map((x) => parseInt(x))

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 [a, b] = readLine().split(" ").map(Number);
    const str = readLine();
    let [ans, seen1, lastIndex] = [0, false, -1];

    for (let i = 0; i < str.length; i++) {
      if (!seen1 && str[i] === "1") {
        seen1 = true;
        lastIndex = i;
        ans += a;
        continue;
      }
      if (str[i] === "1" && str[i - 1] === "1") lastIndex = i;
      if (seen1 && str[i] === "1" && str[i - 1] === "0") {
        ans += Math.min(a, (i - lastIndex - 1) * b);
        lastIndex = i;
      }
    }
    console.log(ans);
  }
}

(()=>{"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 a="local"===process.argv[2],h=t=>{if(a){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 p(){return s[u++]}function f(){return p().split(" ").map((t=>parseFloat(t)))}function c(){return p().split("")}e.default={runMain:h,runEachTest:t=>{h((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:p,nextNumbers:f,nextBigNumbers:function(){return p().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(f());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]=f();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){a&&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,e]=i.default.nextNumbers(),r=i.default.nextCharacters(),n=0,o=!1,s=0;for(let u=0;u<r.length;++u)o||"1"!=r[u]||0!=u&&"0"!=r[u-1]?("1"==r[u]&&"1"==r[u-1]&&(s=u),o&&"1"==r[u]&&"0"==r[u-1]&&(n+=Math.min(t,e*(u-s-1)),i.default.debug(e*(u-s-1)),s=u)):(n+=t,o=!0,s=u);i.default.puts(n)}))},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 [a, b] = io.nextNumbers()
//
//   let s = io.nextCharacters()
//
//   let best = 0
//
//   let hasMined = false
//
//   let lastMineIndex = 0
//
//   for (let i = 0; i < s.length; ++i) {
//     if (!hasMined && s[i] == "1" && (i == 0 || s[i - 1] == "0")) {
//       best += a
//       hasMined = true
//       lastMineIndex = i
//       continue
//     }
//
//     if (s[i] == "1" && s[i - 1] == "1") {
//       lastMineIndex = i
//     }
//
//     if (hasMined && s[i] == "1" && s[i - 1] == "0") {
//       best += Math.min(a, b * (i - lastMineIndex - 1))
//       io.debug(b * (i - lastMineIndex - 1))
//       lastMineIndex = i
//     }
//   }
//
//   io.puts(best)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

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 [a, b] = readLine().split(" ").map(Number);
    const str = readLine();
    let cost1 = 0;
    for (let i = 0; i < str.length; i++) {
      if (str[i] === "1") {
        cost1 += a;
        while (str[i] === "1") i++;
      }
    }
    const lastIndex = str.lastIndexOf("1");
    let [seen, count0] = [false, 0];
    for (let i = 0; i <= lastIndex; i++) {
      if (str[i] === "1" && !seen) seen = true;
      if (seen && str[i] === "0") count0++;
    }
    const cost2 = b * count0 + a;

    console.log(Math.min(cost1, cost2));
  }
}

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 [a, b] = readLine().split(" ").map(Number);
    const str = readLine();
    let [ans, seen1, lastIndex] = [0, false, -1];

    for (let i = 0; i < str.length; i++) {
      if (!seen1 && str[i] === "1") {
        seen1 = true;
        lastIndex = i;
        ans += a;
        continue;
      }
      if (str[i] === "1" && str[i - 1] === "1") lastIndex = i;
      if (seen1 && str[i] === "1" && str[i - 1] === "0") {
        ans += Math.min(a, (i - lastIndex - 1) * b);
      }
    }
    console.log(ans);
  }
}


//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){inLine.push(input);});
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 nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
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 one = nextIntArray();
    var N = one[0];
    var T = one[1];
    var list = nextIntArray();
    var L = {};
    var R = {};
    for(var j = 0; j < N; j++){
      if(L[T - list[j]] == null){
        if(L[list[j]] == null){
          L[list[j]] = 0;
        }
        L[list[j]]++;
        list[j] = 1;
      }else if(R[T - list[j]] == null){
        if(R[list[j]] == null){
          R[list[j]] = 0;
        }
        R[list[j]]++;
        list[j] = 0;
      }else{
        if(L[T - list[j]] > R[T - list[j]]){
          R[list[j]]++;
          list[j] = 1;
        }else{
          L[list[j]]++;
          list[j] = 0;
        }
      }
    }
    output[i] = myconv(list, 8);
  }
  myout(myconv(output, 9));
}

'use strict';

var readline = require('readline');

function tTwoLinesPerStdin() {
  return new Promise(resolve => {
    const stdin = readline.createInterface(process.stdin);
    let t;
    let prevLine;
    let output = [];
    stdin.on('line', line => {
      if (typeof t !== 'number') {
        t = +line;
      } else {
        if (prevLine) {
          output.push([prevLine, line]);
          prevLine = undefined;

          if (output.length === t) {
            resolve(output);
            stdin.close();
          }
        } else {
          prevLine = line;
        }
      }
    });
  });
}

function solve(T, arr) {
  const mid = T / 2;
  let midLeft = true;
  const output = [];

  for (let i = 0; i < arr.length; i++) {
    const element = arr[i];

    if (element === mid) {
      output.push(midLeft ? 1 : 0);
      midLeft = !midLeft;
    } else {
      output.push(element < mid ? 1 : 0);
    }
  }

  return output;
}

async function main() {
  const input = await tTwoLinesPerStdin();

  for (let t = 0; t < input.length; t++) {
    const [line1, line2] = input[t];
    const [T] = line1.split(' ').map(Number).slice(1);
    const a = line2.split(' ').map(Number);
    const answer = solve(T, a);
    console.log(answer.join(' '));
  }
}

main().then();

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, target] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    const arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    const result = [];
    let flag = true;

    for (let i = 0; i < len; i++) {
      const value = arr[i];
      const mid = Math.floor(target / 2);

      if (2 * value === target) {
        result.push(+flag);
        flag = !flag;
      } else if (value <= mid) {
        result.push(0);
      } else {
        result.push(1);
      }
    }

    console.log(result.join(" "));
  }
}

function For(a, b, step, fn) {
  let res;
  if (step > 0) {
    for (let i = a; i <= b; i += step) {
      if ((res = fn(i)) != null) return res;
    }
  } else {
    for (let i = a; i >= b; i += step) {
      if ((res = fn(i)) != null) return res;
    }
  }
}

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

// let p = [2, 3, 5];
// for (let i = 6; i < 1e5; i += 6) {
//   let j, x = i + 1;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
//   x = i + 5;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let n = $(), k = $()
    let a = $(n)
    let s = a.filter(v => v + v == k).length;
    let ii = 0;
    For(0, n - 1, 1, i => {
      if (a[i] + a[i] != k) {
        if (a[i] < k / 2) a[i] = 0;
        else a[i] = 1;
      } else {
        if (ii < s / 2) a[i] = 0;
        else a[i] = 1;
        ii++
      }
    })
    log(a.join(' '))
  }
}

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

    B();
});

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 > 0){
        t--;
        let [n,k] = ti(readline().split(' '));
        let a = ti(readline().split(' '));

        a.sort((a,b) => a-b);
        let count = 0;
        for(let i = 1; i < n; i++){
            if(a[i] < k)
                count += (k-a[i]);
        }
        console.log(Math.floor((count)/a[0]));
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n,k] = ti(readline().split(' '));
        let a = ti(readline().split(' '));

        let map = new Array(1000000008);
        let color = new Array(1000000008);
        for(let i = 0; i < n; i++){
            if(i === 0){
                map[a[i]] = 1;
            }else{
                let x = k-a[i];
                if(color[a[i]] !== undefined){
                    continue;
                }

                if(x >= 0 && map[x] !== undefined){
                    if(color[x] !== undefined){
                        color[a[i]] = color[x] === 1 ? 0 : 1;
                    }else{
                        color[x] = 1;
                        color[a[i]] = 0;
                    }
                }

                map[a[i]] = 1;
            }
        }

        let res = new Array(n);
        for(let i = 0; i < n; i++){
            if(color[a[i]] === undefined)
                res[i] = 0;
            else
                res[i] = color[a[i]];

            if(a[i] === k / 2){
                if(color[a[i]] === 1)
                    color[a[i]] = 0;
                else
                    color[a[i]] = 1;
            }
        }

        for(let i of res)
            console.log(i);
    }
}

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, target] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    const arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    const restricted = {};
    const result = [];

    for (let i = 0; i < len; i++) {
      const value = arr[i];
      const otherValue = Math.abs(target - value);
      if (!restricted[value]) {
        result.push(0);
        restricted[otherValue] = true;
      } else {
        result.push(1);
        restricted[value] = false;
      }
    }

    console.log(result.join(" "));
  }
}

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, target] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    const arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    const result = [];
    let flag = true;

    for (let i = 0; i < len; i++) {
      const value = arr[i];
      const mid = Math.floor(target / 2);

      if (2 * value === target) {
        result.push(+flag);
        flag = !flag;
      } else if (value < mid) {
        result.push(0);
      } else {
        result.push(1);
      }
    }

    console.log(result.join(" "));
  }
}

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

    B();
});

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 > 0){
        t--;
        let [n,k] = ti(readline().split(' '));
        let a = ti(readline().split(' '));

        a.sort((a,b) => a-b);
        let count = 0;
        for(let i = 1; i < n; i++){
            if(a[i] < k)
                count += (k-a[i]);
        }
        console.log(Math.floor((count)/a[0]));
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n,k] = ti(readline().split(' '));
        let a = ti(readline().split(' '));

        let map = new Array(1000000008);

        let res = new Array(n);
        for(let i = 0; i < n; i++){
            if(i === 0){
                map[a[i]] = i;
            }else{
                let x = k-a[i];
                if(x >= 0 && map[x] !== undefined){
                    if(res[map[x]] === undefined){
                        res[i] = 0;
                        res[map[x]] = 1;
                    }
                    else{
                        res[i] = res[map[x]] === 0 ? 1 : 0;
                    }
                }else{
                    map[a[i]] = i;
                }
            }
        }

        for(let i = 0; i < n; i++)
            if(res[i] === undefined)
                res[i] = 0;

        for(let i of res)
            console.log(i);
    }
}

'use strict';

var readline = require('readline');

function tTwoLinesPerStdin() {
  return new Promise(resolve => {
    const stdin = readline.createInterface(process.stdin);
    let t;
    let prevLine;
    let output = [];
    stdin.on('line', line => {
      if (typeof t !== 'number') {
        t = +line;
      } else {
        if (prevLine) {
          output.push([prevLine, line]);
          prevLine = undefined;

          if (output.length === t) {
            resolve(output);
            stdin.close();
          }
        } else {
          prevLine = line;
        }
      }
    });
  });
}

function solve(T, arr) {
  const mid = T / 2;
  let midDone = false;
  const output = [];

  for (let i = 0; i < arr.length; i++) {
    const element = arr[i];

    if (element === mid) {
      output.push(midDone ? 1 : 0);
      midDone = true;
    } else {
      output.push(element < mid ? 1 : 0);
    }
  }

  return output;
}

async function main() {
  const input = await tTwoLinesPerStdin();

  for (let t = 0; t < input.length; t++) {
    const [line1, line2] = input[t];
    const [T] = line1.split(' ').map(Number).slice(1);
    const a = line2.split(' ').map(Number);
    const answer = solve(T, a);
    console.log(answer.join(' '));
  }
}

main().then();


'use strict';

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

class INPUT {
	constructor() {
		this.input = '';
		this.curLine = 0;
	}

	append(str) {
		this.input += str;
	}

	prepare() {
		this.input = this.input.split('\n').map((str) => str.trim());
	}

	readline() {
		return this.input[this.curLine++];
	}

	readInts() {
		return this.readline()
			.split(' ')
			.map((x) => parseInt(x, 10));
	}
}

const input = new INPUT();

process.stdin.on('data', (str) => {
	input.append(str);
});

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

function solve() {
	const [n] = input.readInts();
	const a = input.readInts();
	const pos = {};

	for (let i = 0; i < n; i++) {
		if (!pos[a[i]]) {
			pos[a[i]] = [];
		}

		pos[a[i]].push(i);
	}

	let ans = -1;
	let best = undefined;

	for (const x in pos) {
		const ind = pos[x];

		let bal = 0;
		let mn = 0;
		let mnPos = 0;
		let prv = -1;

		for (let i = 0; i < ind.length; i++) {
			bal -= ind[i] - prv - 1;

			if (bal < mn) {
				mn = bal;
				mnPos = ind[i];
			}

			bal++;

			if (bal - mn > ans) {
				ans = bal - mn;
				best = [x, mnPos + 1, ind[i] + 1];
			}

			prv = ind[i];
		}
	}

	console.log(best[0], best[1], best[2]);
}

function main() {
	let [T] = input.readInts();

	while (T--) {
		solve();
	}
}

var numTestCases = parseInt(readline());
var diceValueMap = {};
var maxDiceValueMap = {};
var maximumScore = 0;
var maximumScoreDice = 0;
var maximumScoreInd = 0;

for (var i = 0; i < numTestCases; i++) {
    var numRounds = parseInt(readline());
    var inpFirstLine = readline().split(" ");
    var diceValueArray = inpFirstLine.map(element => parseInt(element));
    diceValueMap = {};
    maxDiceValueMap = {};
    maximumScore = 1;
    maximumScoreDice = diceValueArray[0];
    maximumScoreInd = 0;
    for (var ind = 0; ind < numRounds; ind++) {
        updateDiceValueMap(ind, diceValueArray[ind]);
    }

    for (var key in maxDiceValueMap) {
        if (maxDiceValueMap[key].cs >= maximumScore) {
            maximumScore = maxDiceValueMap[key].cs;
            maximumScoreInd = maxDiceValueMap[key].ind;
            maximumScoreDice = key;
        }
    }
    var currentScoreValue = 0;
    var diceInd = maximumScoreInd;
    for (; diceInd > 0; diceInd--) {
        if (diceValueArray[diceInd] == maximumScoreDice) {
            currentScoreValue++;
        } else {
            currentScoreValue--;
        }

        if (currentScoreValue >= maximumScore) {
            break;
        }
    }
    print(maximumScoreDice, (diceInd + 1), (maximumScoreInd + 1));
}

function updateDiceValueMap(index, diceValue) {
    var cumulativeScore = 1;
    if (diceValueMap.hasOwnProperty(diceValue)) {
        cumulativeScore = Math.max(1, diceValueMap[diceValue].cs - (index - (diceValueMap[diceValue].ind + 2)));
    } else {
        cumulativeScore = 1;
        diceValueMap[diceValue] = {};
    }

    diceValueMap[diceValue].ind = index;
    diceValueMap[diceValue].cs = cumulativeScore;

    updateMaxDiceValueMap(diceValue);
}

function updateMaxDiceValueMap(diceValue) {
    if (!maxDiceValueMap.hasOwnProperty(diceValue)) {
        maxDiceValueMap[diceValue] = {};
        maxDiceValueMap[diceValue].ind = diceValueMap[diceValue].ind;
        maxDiceValueMap[diceValue].cs = diceValueMap[diceValue].cs;
    } else {
        if (diceValueMap[diceValue].cs >= maxDiceValueMap[diceValue].cs) {
            maxDiceValueMap[diceValue].ind = diceValueMap[diceValue].ind;
            maxDiceValueMap[diceValue].cs = diceValueMap[diceValue].cs;
        }
    }
}

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 = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const map = arr.reduce((o, x, i) => {
        o[x] = o[x] || []
        o[x].push(i)
        return o
    }, {})
    let max = -Infinity, output
    for (let k in map) {
        k = +k
    // console.log(k, map[k])
        const temp = []
        let c = 1
        for (let i = 1; i < map[k].length; i++) {
            const j = map[k][i]
            const p = map[k][i - 1]
            if (j === p + 1) {
                c++
            } else {
                temp.push(c, -(j - p - 1))
                c = 1
            }
        }
        temp.push(c)
        const [ans, l, r] = lcs(temp)
    // console.log(k, temp, ans)
        if (ans > max) {
            max = ans
            let sum = 0
            output = [k, map[k][0], map[k][0]]
            for (let i = 0; i < temp.length; i++) {
                if (l === i) output[1] += sum + 1
                sum += Math.abs(temp[i])
                if (r === i) output[2] += sum
            }
        }
    }
    return output.join(' ')
}
function lcs(arr) {
    let p = 0, l, r
    let ans = -Infinity, range
    for (let i = 0; i < arr.length; i++) {
        if (p > 0) {
            p += arr[i]
            r = i
        } else {
            p = arr[i]
            l = r = i
        }
        // console.log(p)
        if (p > ans) {
            ans = p
            range = [l, r]
        }
    }
    return [ans, ...range]
}

'use strict';

function solve(n, a) {
  const map = new Map();
  for (let [i, num] of a.entries()) {
    if (!map.has(num)) map.set(num, []);
    map.get(num).push(i);
  }
  let res = [1, a[0], 0, 0];
  for (let [num, list] of map) {
    const sum = [];
    let r = 0;
    sum[0] = 1;
    for (let i = 1; i < list.length; i++) {
      const cur = sum[i - 1] - (list[i] - list[i - 1] - 1) + 1;
      sum[i] = Math.max(1, cur);
      if (sum[i] > sum[r]) r = i;
    }
    let l = r;
    while (sum[l] !== 1) l--;
    if (res[0] < sum[r]) {
      res = [sum[r], num, list[l], list[r]];
    }
  }
  const [, x, y, z] = res;
  return `${x} ${y + 1} ${z + 1}`;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

var numTestCases = parseInt(readline());
var diceValueMap = {};
var maximumScore = 0;
var maximumScoreDice = 0;
var maximumScoreInd = 0;

for (var i = 0; i < numTestCases; i++) {
    var numRounds = parseInt(readline());
    var inpFirstLine = readline().split(" ");
    var diceValueArray = inpFirstLine.map(element => parseInt(element));
    diceValueMap = {};
    maximumScore = 1;
    maximumScoreDice = diceValueArray[0];
    maximumScoreInd = 0;
    for (var ind = 0; ind < numRounds; ind++) {
        updateDiceValueMap(ind, diceValueArray[ind]);
    }

    for (var key in diceValueMap) {
        if (diceValueMap[key].cs >= maximumScore) {
            maximumScore = diceValueMap[key].cs;
            maximumScoreInd = diceValueMap[key].ind;
            maximumScoreDice = key;
        }
    }
    var currentScoreValue = 0;
    var diceInd = maximumScoreInd;
    for (; diceInd > 0; diceInd--) {
        if (diceValueArray[diceInd] == maximumScoreDice) {
            currentScoreValue++;
        } else {
            currentScoreValue--;
        }

        if (currentScoreValue >= maximumScore) {
            break;
        }
    }

    print(maximumScoreDice, (diceInd + 1), (maximumScoreInd + 1));
}

function updateDiceValueMap(index, diceValue) {
    var cumulativeScore = 1;
    if (diceValueMap.hasOwnProperty(diceValue)) {
        cumulativeScore = Math.max(1, diceValueMap[diceValue].cs - (index - (diceValueMap[diceValue].ind + 2)));
    } else {
        cumulativeScore = 1;
        diceValueMap[diceValue] = {};
    }

    diceValueMap[diceValue].ind = index;
    diceValueMap[diceValue].cs = cumulativeScore;
}

var numTestCases = parseInt(readline());
var diceValueMap = {};
var maximumScore = 0;
var maximumScoreDice = 0;
var maximumScoreInd = 0;

for (var i = 0; i < numTestCases; i++) {
    var numRounds = parseInt(readline());
    var inpFirstLine = readline().split(" ");
    var diceValueArray = inpFirstLine.map(element => parseInt(element));
    diceValueMap = {};
    maximumScore = 1;
    maximumScoreDice = diceValueArray[0];
    maximumScoreInd = 0;
    for (var ind = 0; ind < numRounds; ind++) {
        updateDiceValueMap(ind, diceValueArray[ind]);
    }
    for (var key in diceValueMap) {
        if (diceValueMap[key].cs >= maximumScore) {
            maximumScore = diceValueMap[key].cs;
            maximumScoreInd = diceValueMap[key].ind;
            maximumScoreDice = key;
        }
    }
    var currentScoreValue = 0;
    var diceInd = maximumScoreInd;
    for (; diceInd > 0 && currentScoreValue < maximumScore; diceInd--) {
        if (diceValueArray[diceInd] == maximumScoreDice) {
            currentScoreValue++;
        }
    }
    print(maximumScoreDice, (diceInd + 1), (maximumScoreInd + 1));
}

function updateDiceValueMap(index, diceValue) {
    var cumulativeScore = 1;
    if (diceValueMap.hasOwnProperty(diceValue)) {
        cumulativeScore = Math.max(1, diceValueMap[diceValue].cs - (index - (diceValueMap[diceValue].ind + 2)));
    } else {
        cumulativeScore = 1;
        diceValueMap[diceValue] = {};
    }

    diceValueMap[diceValue].ind = index;
    diceValueMap[diceValue].cs = cumulativeScore;
}

var numTestCases = parseInt(readline());
var diceValueMap = {};
var maximumScore = 0;
var maximumScoreDice = 0;
var maximumScoreInd = 0;

for (var i = 0; i < numTestCases; i++) {
    var numRounds = parseInt(readline());
    var inpFirstLine = readline().split(" ");
    var diceValueArray = inpFirstLine.map(element => parseInt(element));
    diceValueMap = {};
    maximumScore = 1;
    maximumScoreDice = diceValueArray[0];
    maximumScoreInd = 0;
    for (var ind = 0; ind < numRounds; ind++) {
        updateDiceValueMap(ind, diceValueArray[ind]);
    }
    for (var key in diceValueMap) {
        if (diceValueMap[key].cs >= maximumScore) {
            maximumScore = diceValueMap[key].cs;
            maximumScoreInd = diceValueMap[key].ind;
            maximumScoreDice = key;
        }
    }
    var currentScoreValue = 0;
    var diceInd = maximumScoreInd;
    for (; diceInd > 0 && currentScoreValue < maximumScore; diceInd--) {
        if (diceValueArray[diceInd] == maximumScoreDice) {
            currentScoreValue++;
        }
    }
    print(maximumScoreDice, " ", diceInd + 1, " ", maximumScoreInd + 1);
}

function updateDiceValueMap(index, diceValue) {
    var cumulativeScore = 1;
    if (diceValueMap.hasOwnProperty(diceValue)) {
        cumulativeScore = Math.max(1, diceValueMap[diceValue].cs - (index - (diceValueMap[diceValue].ind + 2)));
    } else {
        cumulativeScore = 1;
        diceValueMap[diceValue] = {};
    }

    diceValueMap[diceValue].ind = index;
    diceValueMap[diceValue].cs = cumulativeScore;
}

'use strict';

function solve(n, a) {
  const map = new Map();
  for (let [i, num] of a.entries()) {
    if (!map.has(num)) map.set(num, []);
    map.get(num).push(i);
  }
  let res = [1, a[0], 0, 0];
  for (let [num, list] of map) {
    const sum = [];
    let r = 0;
    sum[0] = 1;
    for (let i = 1; i < list.length; i++) {
      var _list;
      const cur = sum[i - 1] - (list[i] - ((_list = list[i - 1]) !== null && _list !== void 0 ? _list : -1) - 1) + 1;
      sum[i] = Math.max(1, cur);
      if (sum[i] > sum[r]) r = i;
    }
    let l = r;
    while (l - 1 >= 0 && sum[l - 1] <= sum[l]) l--;
    if (res[0] < sum[r]) {
      res = [sum[r], num, list[l], list[r]];
    }
  }
  const [, x, y, z] = res;
  return `${x} ${y + 1} ${z + 1}`;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function solve(n, a) {
  const map = new Map();
  for (let [i, num] of a.entries()) {
    if (!map.has(num)) map.set(num, []);
    map.get(num).push(i);
  }
  let res = [1, a[0], 0, 0];
  for (let [num, list] of map) {
    const sum = [];
    let l = 0,
        r = 0;
    sum[0] = 1;
    for (let i = 1; i < list.length; i++) {
      var _list;
      const cur = sum[i - 1] - (list[i] - ((_list = list[i - 1]) !== null && _list !== void 0 ? _list : -1) - 1) + 1;
      if (cur > 0) {
        r = i;
      } else {
        l = i;
        r = i;
      }
      sum[i] = Math.max(0, cur);
      if (res[0] < sum[i]) {
        res = [sum[i], num, list[l], list[r]];
      }
    }
  }
  const [, x, y, z] = res;
  return `${x} ${y + 1} ${z + 1}`;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});


'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = read(),
        b = rns();
  const dp = Array.from({
    length: n
  }, () => [0, 0]);
  for (let i = 0; i < n; i++) {
    if (a[i] === '1') {
      var _dp$, _dp, _dp$2, _dp2, _dp$3, _dp3, _b;
      dp[i][1] = Math.max((_dp$ = (_dp = dp[i - 1]) === null || _dp === void 0 ? void 0 : _dp[0]) !== null && _dp$ !== void 0 ? _dp$ : 0, (_dp$2 = (_dp2 = dp[i - 1]) === null || _dp2 === void 0 ? void 0 : _dp2[1]) !== null && _dp$2 !== void 0 ? _dp$2 : 0) + b[i];
      dp[i][0] = ((_dp$3 = (_dp3 = dp[i - 1]) === null || _dp3 === void 0 ? void 0 : _dp3[0]) !== null && _dp$3 !== void 0 ? _dp$3 : 0) + ((_b = b[i - 1]) !== null && _b !== void 0 ? _b : 0);
    } else {
      var _dp$4, _dp4, _dp$5, _dp5;
      dp[i][0] = Math.max((_dp$4 = (_dp4 = dp[i - 1]) === null || _dp4 === void 0 ? void 0 : _dp4[0]) !== null && _dp$4 !== void 0 ? _dp$4 : 0, (_dp$5 = (_dp5 = dp[i - 1]) === null || _dp5 === void 0 ? void 0 : _dp5[1]) !== null && _dp$5 !== void 0 ? _dp$5 : 0);
    }
  }
  return Math.max(dp[n - 1][0], dp[n - 1][1]);
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r?\n/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let lid = iInpArr1();
    let arr = iInpArr();
    let narr = [];
    let lidc = 0,
      zero = -1;
    if (n === 1) {
      if (lid[0] === 1) console.log(arr[0]);
      else console.log(0);
      continue;
    }
    for (let i = 0; i < n; i++) {
      if (lid[i] === 1) {
        if (zero !== -1 && arr[zero] > arr[i]) {
          lid[zero] = 1;
          lid[i] = 0;
          zero = i;
        }
      } else zero = i;
    }
    let sum = 0;
    for (let i = 0; i < n; i++) if (lid[i] === 1) sum += arr[i];
    console.log(sum);
  }
};
solve();

/*
* auther yeling
*
*
*/
'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 print(str) {
    console.log(str);
}

// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');
// main();
// testOutput();

function begin(n, lids, vals) {
    //print(n, lids, vals);
    let sum = 0;
    let dp = new Array(n).fill(0).map(() => new Array(2).fill(0));
    //dp[i][0] 表示i位不移动
    //dp[i][1] 表示i位移动

    for(let i = 0; i < n; i++) {
        if(lids[i] == 1) {
            if(i == 0) {
                dp[i][0] = vals[i];
            } else if(lids[i - 1] == 0) {
                let pre = Math.max(dp[i-1][0], dp[i-1][1]);
                dp[i][0] = pre + vals[i];
                dp[i][1] = pre + vals[i-1];
            } else if(lids[i - 1] == 1) {
                dp[i][1] = Math.max(dp[i][1], dp[i-1][1] + vals[i-1]);
                dp[i][0] = Math.max(dp[i][1], dp[i-1][1] + vals[i]);
                dp[i][0] = Math.max(dp[i][0], dp[i-1][0] + vals[i]);
            }
        } else {
            if(i > 0) {
                dp[i][0] = dp[i-1][0];
                dp[i][1] = dp[i-1][1];
            }
        }

    }
    print(Math.max(dp[n-1][0], dp[n-1][1]));
}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = parseInt(readline(), 10);
        var lids = readline()
            .trim()
            .split('')
            .map((y) => parseInt(y, 10));
        var vals = readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
        begin(n, lids, vals);
    }
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let lid = iInpArr1();
    let arr = iInpArr();
    let narr = [];
    let lidc = 0,
      zero = -1;
    if (n === 1) {
      if (lid[0] === 1) console.log(arr[0]);
      else console.log(0);
      continue;
    }
    for (let i = 1; i < n; i++) {
      if (lid[i] === 1) {
        if (zero !== -1 && arr[zero] > arr[i]) {
          lid[zero] = 1;
          lid[i] = 0;
          zero = i;
        }
      } else zero = i;
    }
    let sum = 0;
    for (let i = 0; i < n; i++) if (lid[i] === 1) sum += arr[i];
    console.log(sum);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let lid = iInpArr1();
    let arr = iInpArr();
    let narr = [];
    let lidc = 0,
      zero = 0;
    if (n === 1) {
      if (lid[0] === 1) console.log(arr[0]);
      else console.log(0);
      continue;
    }
    for (let i = 1; i < n; i++) {
      if (lid[i] === 1) {
        if (arr[zero] > arr[i]) {
          lid[zero] = 1;
          lid[i] = 0;
          zero = i;
        }
      } else zero = i;
    }
    let sum = 0;
    for (let i = 0; i < n; i++) if (lid[i] === 1) sum += arr[i];
    console.log(sum);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let lid = iInpArr1();
    let arr = iInpArr();
    let narr = [];
    let lidc = 0,
      zero = 0;
    for (let i = 0; i < n; i++) if (lid[i] === 1) lidc++;
    for (let i = 1; i < n; i++) {
      if (lid[i] === 1) {
        if (arr[zero] > arr[i]) {
          lid[zero] = 1;
          lid[i] = 0;
          zero = i;
        }
      } else zero = i;
    }
    let sum = 0;
    for (let i = 0; i < n; i++) if (lid[i] === 1) sum += arr[i];
    console.log(sum);
  }
};
solve();

/*
* auther yeling
*
*
*/
'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 print(str) {
    console.log(str);
}

// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');
// main();
// testOutput();

function begin(n, lids, vals) {
    //print(n, lids, vals);
    let sum = 0;
    let dp = new Array(n).fill(0).map(() => new Array(2).fill(0));
    //dp[i][0] 表示i位不移动
    //dp[i][1] 表示i位移动

    for(let i = 0; i < n; i++) {
        if(lids[i] == 1) {
            if(i == 0) {
                dp[i][0] = dp[i][1] = vals[i];
            } else if(lids[i - 1] == 0) {
                let pre = Math.max(dp[i-1][0], dp[i-1][1]);
                dp[i][0] = pre + vals[i];
                dp[i][1] = pre + vals[i-1];
            } else if(lids[i - 1] == 1) {
                dp[i][1] = Math.max(dp[i][1], dp[i-1][1] + vals[i-1]);
                dp[i][0] = Math.max(dp[i][1], dp[i-1][1] + vals[i]);
                dp[i][0] = Math.max(dp[i][0], dp[i-1][0] + vals[i]);
            }
        } else {
            if(i > 0) {
                dp[i][0] = dp[i-1][0];
                dp[i][1] = dp[i-1][1];
            }
        }

    }
    print(Math.max(dp[n-1][0], dp[n-1][1]));
}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = parseInt(readline(), 10);
        var lids = readline()
            .trim()
            .split('')
            .map((y) => parseInt(y, 10));
        var vals = readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
        begin(n, lids, vals);
    }
}

/*
* auther yeling
*
*
*/
'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 print(str) {
    console.log(str);
}

// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');
// main();
// testOutput();

function begin(n, lids, vals) {
    //print(n, lids, vals);
    let sum = 0;
    let stack = new Array();
    for(let i = 0; i < n; i++) {
        stack.push(vals[i]);
        if(lids[i] == 1) {
            let max = 0;
            let maxIndex = 0;
            for(let j = 0; j < stack.length; j++) {
                if(max < stack[j]) {
                    max = stack[j];
                    maxIndex = j;
                }
            }
            sum += max;
            stack.splice(maxIndex, 1);
        }
    }
    print(sum);
}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = parseInt(readline(), 10);
        var lids = readline()
            .trim()
            .split('')
            .map((y) => parseInt(y, 10));
        var vals = readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
        begin(n, lids, vals);
    }
}


function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    findNext();
  }
};

function findNext() {
    var pointsNum = +readline();
    var points = {};
    for (var j = 0; j < pointsNum; j++) {
        var xy = readline().split(' ').map(Number);
        var x = xy[0];
        var y = xy[1];
        if (!points[x]) {
            points[x] = {
                min: 1000,
                max: 0
            }
        }
        if (y < points[x].min) {
            points[x].min = y;
        }
        if (y > points[x].max) {
            points[x].max = y;
        }
    }
    var keyss = Object.keys(points).map(Number).sort(byNum);
    var points2 = {};
    for (var k = 0; k < keyss.length; k++) {
        points2[keyss[k]] = points[keyss[k]]
    }
    var curr = {
        x: 0,
        y: 0
    };
    var res = '';
    for (var m = 0; m < keyss.length; m++) {
        var nextX = keyss[m];
        if (points2[nextX].min < curr.y) {
            print('NO');
            return;
        }

        for (var a = curr.x; a < nextX; a++) {
            res += 'R';
        }
        curr.x = nextX;

        for (var b = curr.y; b < points2[nextX].max; b++) {
            res += 'U';
        }
        curr.y = points2[nextX].max;
        // print(res, nextX, curr, keys);
    }
    print('YES');
    print(res);
};

function byNum(a, b) { return a - b };
main();

function findPath (array){
	var x = 0, y = 0;
	var found = true;
	var path = "";
	for (var i in array){
		while (1){
			if (array[i][0] > x){
				path+='R';
				x+=1;
			}
			else if(array[i][1] > y){
				path +='U';
				y+=1;
			}
			else if(x == array[i][0] && y == array[i][1]){
				break;
			}
			else{
				found = false;
				break
			}
		}
		if (!found){
			break;
		}
	}
	if(found){
		print('YES');
		print(path);
	}
	else{
		print('NO');
	}
}

var queries = parseInt(readline())
for(var i = 0 ; i < queries; i++){
var array = [];
var elements = parseInt(readline());
for (var j = 0; j< elements; j++){
	var entries = readline().split(' ').map((val)=>{
		return parseInt(val);
	})
	array.push(entries)
}
array.sort((a,b)=>{
	if (a[0]!= b[0]){
		return a[0] - b[0];
	}
	else{
		return a[1] - b[1];
	}})
findPath(array)
}

'use strict'

const problem = (a) => {
    let r = '';
    let prevX = 0;
    let min = 0;
    let max = 0;
    const keys = Object.keys(a).sort((x, y) => x - y);
    for (let i = 0; i < keys.length; i++) {
        const x = keys[i];
        if (max > a[x].min) return 'NO';
        r += 'R'.repeat(x - prevX) + 'U'.repeat(a[x].max - max);
        max = a[x].max;
        min = a[x].min;
        prevX = x;
    }
    return `YES\n${r}`;
}

let t = +readline();
while(t--) {
    const n = +readline();
    const a = Array.from({ length: n }, () => readline().split(' ').map(Number))
        .reduce((r, t) => {
            const x = t[0];
            const y = t[1];
            if (!r[x]) {
                r[x] = { min: y, max: y };
            } else {
                r[x].min = Math.min(r[x].min, y);
                r[x].max = Math.max(r[x].max, y);
            }
            return r;
        }, {});
    print(problem(a));
}

Main();
function myout(t){print(t);}//standard output
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main() {
  var t = myconv(readline(),1);
  var output = [];
  for(var i = 0; i < t; i++){
      var n = myconv(readline(),1);
      var list = new Array(n);
      var underX = 0;
      var underY = 0;
      for(var j = 0; j < n; j++){
          var tmp = myconv(readline(),4);
          tmp = [tmp[0],tmp[1]];
          list[j] = tmp;
      }
      list.sort(function(a,b){
          var tmpa = a[0] + a[1];
          var tmpb = b[0] + b[1];
          return tmpa - tmpb;
      });
      var out = "";
      var breakFlg = false;
      for(var j = 0; j < n; j++){
          var x = list[j][0];
          var y = list[j][1];
          if(underX <= x && underY <= y){
              for(var k = 0; k < Math.abs(x - underX); k++){
                  out += "R";
              }
              for(var k = 0; k < Math.abs(y - underY); k++){
                  out += "U";
              }
              underX = x;
              underY = y;
          }else{
              breakFlg = true;
              break;
          }
      }
      if(!breakFlg){
          output.push("YES");
          output.push(out);
      }else{
          output.push("NO");
      }
  }
  myout(myconv(output,9));
}

var t = parseInt(readline(), 10);

for(var i=1; i<=t; i++) {
    var n = parseInt(readline(), 10);
    var path = '', x = 0, y = 0, valid = true, xy = [];

    for(var j=1; j<=n; j++) {
        var inp = readline().split(' ').map(el => parseInt(el, 10));
        xy.push({x: inp[0], y: inp[1]});
    }

    xy.sort((a,b) => (a.x + a.y) - (b.x + b.y));

    for(var k=0; k<n; k++) {
        if(xy[k].x < x) {
            valid = false;
            break;
        } else {
            for(var m=1; m<=(xy[k].x - x); m++) {
                path += 'R';
            }

            x = xy[k].x;

        }

        if(xy[k].y < y) {
            valid = false;
            break;
        } else {
            for(var m=1; m<=(xy[k].y - y); m++) {
                path += 'U';
            }

            y = xy[k].y;

        }
    }

    if(valid) {
        print('YES');
        print(path);
    } else print('NO');
}

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

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

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

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

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  let i = 0
  const t = readInt(input, i++)

  for(let j = 0; j < t; j++) {
    const n = readInt(input, i++)
    const as = new Array(n)
    for(let k = 0; k < n; k++) {
      as[k] = readInts(input, i++)
    }

    as.sort((a, b) => {
      if(a[0] !== b[0]) return a[0] - b[0]
      else return a[1] - b[1]
    })
    // wr(as)
    let x = 0
    let y = 0
    let f = true
    let s = ""
    for(let k = 0; k < n && f; k++) {
      const [x1, y1] = as[k]
      if(x1 < x || y1 < y || (x1 === x && y1 === y)) f = false
      else if(x1 === x) {
        let t = y1 - y
        while(t--) s += "U"
        y = y1
      }
      else if(y1 === y) {
        let t = x1 - x
        while(t--) s += "R"
        x = x1
      }
      else {
        let t = x1 - x
        while(t--) s += "R"
        t = y1 - y
        while(t--) s += "U"
        x = x1
        y = y1
      }
    }
    if(!f) wr('NO')
    else {
      wr('YES')
      wr(s)
    }
  }
}

'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 readint() {
    let line = readline().split(' ').map(function(num) {
        return parseInt(num);
    });
    return line;
}

function readfloat() {
    let line = readline().split(' ').map(function(num) {
        return parseFloat(num);
    });
    return line;
}

function print(x) {
    console.log(x);
}

function write(x) {
    process.stdout.write(x);
}
function main() {
    let t = readline();
    //go go bro!!!
    while(t--) {
        const n = readline();
        let i = n;
        let points = [];
        while(i--) {
            points.push(readint());
        }
        points.sort(function(a,b) {
            if(a[0] > b[0]) {
                return 1;
            } else if(a[0] < b[0]) {
                return -1;
            } else {
                if(a[1] > b[1]) {
                    return 1;
                } else {
                    return -1;
                }
            }
        });
        let printable = true;
        let ans = [];
        let prev = [0,0];
        for(let i = 0; i < n; ++i) {
            let curr = points[i];
            if(prev[1] > curr[1]) {
                print("NO");
                printable = false;
                break;
            } else {
                for(let j = 0; j < curr[0] - prev[0]; j++) {
                    ans.push('R');
                }
                for(let j = 0; j < curr[1] - prev[1]; j++) {
                    ans.push('U');
                }
            }
            prev = curr;
        }
        if(printable) {
            print('YES');
            print(ans.join(''));
        }
    }
}

var tests = parseInt(readline());
while(tests--){
  var n =  parseInt(readline());
  var packs = [];
  var path='';
  var _x,_y;
  _x=_y=0;
  for(var i=0;i<n;i++){
      packs.push(readline().split(' ').map(function(a){
          return parseInt(a);
      }));
  }
  packs.sort(function(a,b){
      if(a[0]!=b[0]){
          return a[0]-b[0];
      }else if(a[1] != b[1]){
          return a[1]-b[1];
      }
  });
    for(var j=0;j<packs.length;j++){
        var x = packs[j][0];
        var y = packs[j][1];
        if(x >= _x && y >=_y){
            for(var k=0;k<(x-_x);k++){
                path +='R';
            }
            for(var k=0;k<(y-_y);k++){
                path +='U';
            }
            _x = x;
            _y = y;
        }else if(_y > y){
            path="";
            break;
        }
    }
    if(path!=''){
        print("YES");
        print(path);
    }else{
        print("NO");
    }
}

function findPath (array){
	var x = 0, y = 0;
	var found = true;
	var path = "";
	for (var i in array){
		while (1){
			if (array[i][0] > x){
				path+='R';
				x+=1;
			}
			else if(array[i][1] > y){
				path +='U';
				y+=1;
			}
			else if(x == array[i][0] && y == array[i][1]){
				break;
			}
			else{
				found = false;
				break
			}
		}
		if (!found){
			break;
		}
	}
	if(found){
		print('YES');
		print(path);
	}
	else{
		print('NO');
	}
}

var queries = parseInt(readline())
for(var i = 0 ; i < queries; i++){
var array = [];
var elements = parseInt(readline());
for (var i = 0; i< elements; i++){
	var entries = readline().split(' ').map((val)=>{
		return parseInt(val);
	})
	array.push(entries)
}
array.sort((a,b)=>{
	if (a[0]!= b[0]){
		return a[0] - b[0];
	}
	else{
		return a[1] - b[1];
	}})
findPath(array)
}

'use strict'

const problem = (a) => {
    let r = '';
    let prevX = 0;
    let min = 0;
    let max = 0;
    for (let x in a) {
        if (max > a[x].min) return 'NO';
        r += 'R'.repeat(x - prevX) + 'U'.repeat(a[x].max - max);
        max = a[x].max;
        min = a[x].min;
        prevX = x;
    }
    return `YES\n${r}`;
}

let t = +readline();
while(t--) {
    const n = +readline();
    const a = Array.from({ length: n }, () => readline().split(' ').map(Number))
        .reduce((r, t) => {
            const x = t[0];
            const y = t[1];
            if (!r[x]) {
                r[x] = { min: y, max: y };
            } else {
                r[x].min = Math.min(r[x].min, x);
                r[x].max = Math.max(r[x].max, y);
            }
            return r;
        }, {});
    print(problem(a));
}

'use strict'

const problem = (a) => {
    let r = '';
    let prevX = 0;
    let prevY = 0;
    for (let x in a) {
        if (a[x] < prevY) return 'NO';
        r += 'R'.repeat(x - prevX) + 'U'.repeat(a[x] - prevY)
        prevY = a[prevX = x];
    }
    return `YES\n${r}`;

}

let t = +readline();
while(t--) {
    const n = +readline();
    const a = Array.from({ length: n }, () => readline().split(' ').map(Number))
        .reduce((r, t) => { r[t[0]] = Math.max(r[t[0]] || 0, t[1]); return r; }, {});
    print(problem(a));
}

'use strict'

const problem = (a) => {
    let r = '';
    let prevX = 0;
    let prevY = 0;
    const keys = Object.keys(a).sort((x, y) => x - y);
    for (let i = 0; i < keys.length; i++) {
        const x = keys[i];
        if (a[x] < prevY) return 'NO';
        r += 'R'.repeat(x - prevX) + 'U'.repeat(a[x] - prevY);
        prevY = a[prevX = x];
    }
    return `YES\n${r}`;
}

let t = +readline();
while(t--) {
    const n = +readline();
    const a = Array.from({ length: n }, () => readline().split(' ').map(Number))
        .reduce((r, t) => { r[t[0]] = Math.max(r[t[0]] || 0, t[1]); return r; }, {});
    print(problem(a));
}

'use strict'

const problem = (a) => {
    let r = '';
    let prevX = 0;
    let min = 0;
    let max = 0;
    const keys = Object.keys(a).sort((x, y) => x - y);
    for (let i = 0; i < keys.length; i++) {
        const x = keys[i];
        if (max > a[x].min) return 'NO';
        r += 'R'.repeat(x - prevX) + 'U'.repeat(a[x].max - max);
        max = a[x].max;
        min = a[x].min;
        prevX = x;
    }
    return `YES\n${r}`;
}

let t = +readline();
while(t--) {
    const n = +readline();
    const a = Array.from({ length: n }, () => readline().split(' ').map(Number))
        .reduce((r, t) => {
            const x = t[0];
            const y = t[1];
            if (!r[x]) {
                r[x] = { min: y, max: y };
            } else {
                r[x].min = Math.min(r[x].min, x);
                r[x].max = Math.max(r[x].max, y);
            }
            return r;
        }, {});
    print(problem(a));
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    findNext();
  }
}

function findNext() {
    var pointsNum = +readline();
    var points = {};
    for (var j = 0; j < pointsNum; j++) {
        var xy = readline().split(' ').map(Number);
        var x = xy[0];
        var y = xy[1];
        if (!points[x]) {
            points[x] = {
                min: 1000,
                max: 0
            }
        }
        if (y < points[x].min) {
            points[x].min = y;
        }
        if (y > points[x].max) {
            points[x].max = y;
        }
    }
    var keyss = Object.keys(points).map(Number).sort(byNum);
    var points2 = {};
    for (var k = 0; k < keyss.length; k++) {
        points2[keyss[k]] = points[keyss[k]]
    }
    print(points2);
    var curr = {
        x: 0,
        y: 0
    };
    var res = '';
    for (var m = 0; m < keyss.length; m++) {
        var nextX = keyss[m];
        if (points2[nextX].min < curr.y) {
            print('NO');
            return;
        }

        for (var a = curr.x; a < nextX; a++) {
            res += 'R';
        }
        curr.x = nextX;

        for (var b = curr.y; b < points2[nextX].max; b++) {
            res += 'U';
        }
        curr.y = points2[nextX].max;
        // print(res, nextX, curr, keys);
    }
    print('YES');
    print(res);
};

function byNum(a, b) { return a - b }

main();

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    findNext();
  }
}

function findNext() {
    var pointsNum = +readline();
    var points = {};
    for (var j = 0; j < pointsNum; j++) {
        var xy = readline().split(' ').map(Number);
        var x = xy[0];
        var y = xy[1];
        if (!points[x]) {
            points[x] = {
                min: 1000,
                max: 0
            }
        }
        if (y < points[x].min) {
            points[x].min = y;
        }
        if (y > points[x].max) {
            points[x].max = y;
        }
    }
    var keyss = Object.keys(points).sort(byNum);
    var points2 = {};
    for (var k = 0; k < keyss.length; k++) {
        points2[keyss[k]] = points[keyss[k]]
    }
    // print(points2);
    var curr = {
        x: 0,
        y: 0
    };
    var res = '';
    for (var m = 0; m < keyss.length; m++) {
        var nextX = keyss[m];
        for (var a = curr.x; a < nextX; a++) {
            res += 'R';
        }
        curr.x = nextX;
        if (points2[nextX].min < curr.y) {
            print('NO');
            return;
        }
        for (var b = curr.y; b < points2[nextX].max; b++) {
            res += 'U';
        }
        curr.y = points2[nextX].max;
        // print(res, nextX, curr, keys);
    }
    print('YES');
    print(res);
};

function byNum(a, b) { return a - b };

main()

var t = parseInt(readline(), 10);

for(var i=1; i<=t; i++) {
    var n = parseInt(readline(), 10);
    var path = '', x = 0, y = 0, valid = true, xy = [];

    for(var j=1; j<=n; j++) {
        var inp = readline().split(' ').map(el => parseInt(el, 10));
        xy.push({x: inp[0], y: inp[1]});
    }

    xy.sort((a,b) => a.y - b.y);
    xy.sort((a,b) => a.x - b.x);

    for(var k=0; k<n; k++) {
        if(xy[k].x < x) {
            valid = false;
            break;
        } else {
            for(var m=1; m<=(xy[k].x - x); m++) {
                path += 'R';
            }

            x = xy[k].x;

        }

        if(xy[k].y < y) {
            valid = false;
            break;
        } else {
            for(var m=1; m<=(xy[k].y - y); m++) {
                path += 'U';
            }

            y = xy[k].y;

        }
    }

    if(valid) {
        print('YES');
        print(path);
    } else print('NO');
}

var t = parseInt(readline(), 10);

for(var i=1; i<=t; i++) {
    var n = parseInt(readline(), 10);
    var path = '', x = 0, y = 0, valid = true, xy = [];

    for(var j=1; j<=n; j++) {
        var inp = readline().split(' ').map(el => parseInt(el, 10));
        xy.push({x: inp[0], y: inp[1]});
    }

    xy.sort((a,b) => a.x - b.x);
    xy.sort((a,b) => a.y - b.y);

    for(var k=0; k<n; k++) {
        if(xy[k].x < x) {
            valid = false;
            break;
        } else {
            for(var m=1; m<=(xy[k].x - x); m++) {
                path += 'R';
            }

            x = xy[k].x;

        }

        if(xy[k].y < y) {
            valid = false;
            break;
        } else {
            for(var m=1; m<=(xy[k].y - y); m++) {
                path += 'U';
            }

            y = xy[k].y;

        }
    }

    if(valid) {
        print('YES');
        print(path);
    } else print('NO');
}

function increment(npacks,packs){
    packs = packs.sort(function(a,b){
        return (a[0] - b[0]);
    });
  var curX = 0;
  var curY = 0;
  var flag = false;
  for (var i = 0; i < npacks; i++) {
    nextX = packs[i][0];
    nextY = packs[i][1];
    if (nextX < curX && nextY > curY) {
      flag = true;
    } else if (nextY < curY && nextX > curX) {
      flag = true;
    }
    curX = nextX;
    curY = nextY;
  }
  if (flag) {
    print("NO");
    return false;
  } else {
    print("YES");
    curX = 0;
    curY = 0;
    var remains = packs;
    var path = "";
    var cur = [];
    while (remains.length) {
      nextX = remains[0][0];
      nextY = remains[0][1];
      cur.push(remains[0]);
      remains.splice(0, 1);
      for (var j = 1; j < remains.length; j++) {
        if (remains[j][0] == nextX) {
          cur.push(remains[j]);
          remains.splice(j, 1);
        }
      }
      cur.sort();
      var rMoves = nextX - curX;
      if (nextX > curX) {
        for (var a = 0; a < rMoves; a++) {
          path += 'R';
          curX++;
        }
      }
      for (var b in cur) {
        var uMoves = nextY - curY;
        for (var r = 0; r < uMoves; r++) {
          path += 'U';
          curY++;
        }
      }
      cur = [];
    }
    if(path.length>0){
    		print(path);
        return true;
    }else{
    	return false;
    }
  }
}

var t = parseInt(readline());
while(t--){
    var npacks = parseInt(readline());
    var packs = [];
    for (var l = 0; l < npacks; l++) {
        packs.push(readline().split(' ').map((val)=>{return parseInt(val)}));

    }
    increment(npacks,packs);
}

function increment(npacks,packs){
    packs = packs.sort(function(a,b){
        if(a[0]!=b[0]){
            return (a[0] - b[0]);
        }else{
            return (a[1] - b[1]);
        }
    });
  var curX = 0;
  var curY = 0;
  var flag = false;
  for (var i = 0; i < npacks; i++) {
    nextX = packs[i][0];
    nextY = packs[i][1];
    if (nextX < curX && nextY > curY) {
      flag = true;
    } else if (nextY < curY && nextX > curX) {
      flag = true;
    }
    curX = nextX;
    curY = nextY;
  }
  if (flag) {
    print("NO");
    return false;
  } else {
    print("YES");
    curX = 0;
    curY = 0;
    var remains = packs;
    var path = "";
    var cur = [];
    while (remains.length) {
      nextX = remains[0][0];
      nextY = remains[0][1];
      cur.push(remains[0]);
      remains.splice(0, 1);
      for (var j = 1; j < remains.length; j++) {
        if (remains[j][0] == nextX) {
          cur.push(remains[j]);
          remains.splice(j, 1);
        }
      }
      cur.sort();
      var rMoves = nextX - curX;
      if (nextX > curX) {
        for (var a = 0; a < rMoves; a++) {
          path += 'R';
          curX++;
        }
      }
      for (var b in cur) {
        var uMoves = nextY - curY;
        for (var r = 0; r < uMoves; r++) {
          path += 'U';
          curY++;
        }
      }
      cur = [];
    }
    if(path.length>0){
    		print(path);
        return true;
    }else{
    	return false;
    }
  }
}

var t = parseInt(readline());
while(t--){
    var npacks = parseInt(readline());
    var packs = [];
    for (var l = 0; l < npacks; l++) {
        packs.push(readline().split(' ').map((val)=>{return parseInt(val)}));

    }
    increment(npacks,packs);
}

function increment(npacks,packs){
    packs = packs.sort(function(a,b){
        return (a[0] - b[0]);
    });
  var curX = 0;
  var curY = 0;
  var flag = false;
  for (var i = 0; i < npacks; i++) {
    nextX = packs[i][0];
    nextY = packs[i][1];
    if (nextX < curX && nextY > curY) {
      flag = true;
    } else if (nextY < curY && nextX > curX) {
      flag = true;
    }
    curX = nextX;
    curY = nextY;
  }
  if (flag) {
    print("NO");
    return false;
  } else {
    print("YES");
    curX = 0;
    curY = 0;
    var remains = packs;
    var path = "";
    var cur = [];
    while (remains.length) {
      nextX = remains[0][0];
      nextY = remains[0][1];
      cur.push(remains[0]);
      remains.splice(0, 1);
      for (var j = 1; j < remains.length; j++) {
        if (remains[j][0] == nextX) {
          cur.push(remains[j]);
          remains.splice(j, 1);
        }
      }
      cur.sort(function(a,b){
        return (a[0] - b[0]);
        });
      var rMoves = nextX - curX;
      if (nextX > curX) {
        for (var a = 0; a < rMoves; a++) {
          path += 'R';
          curX++;
        }
      }
      for (var b in cur) {
        var uMoves = nextY - curY;
        for (var r = 0; r < uMoves; r++) {
          path += 'U';
          curY++;
        }
      }
      cur = [];
    }
    if(path.length>0){
    		print(path);
        return true;
    }else{
    	return false;
    }
  }
}

var t = parseInt(readline());
while(t--){
    var npacks = parseInt(readline());
    var packs = [];
    for (var l = 0; l < npacks; l++) {
        packs.push(readline().split(' ').map((val)=>{return parseInt(val)}));

    }
    increment(npacks,packs);
}

function increment(npacks,packs){
  var curX = 0;
  var curY = 0;
  var flag = false;
  for (var i = 0; i < npacks; i++) {
    nextX = packs[i][0];
    nextY = packs[i][1];
    if (nextX < curX && nextY > curY) {
      flag = true;
    } else if (nextY < curY && nextX > curX) {
      flag = true;
    }
    curX = nextX;
    curY = nextY;
  }
  if (flag) {
    print("NO");
    return false;
  } else {
    print("YES");
    curX = 0;
    curY = 0;
    var remains = packs;
    var path = "";
    var cur = [];
    while (remains.length) {
      nextX = remains[0][0];
      nextY = remains[0][1];
      cur.push(remains[0]);
      remains.splice(0, 1);
      for (var j = 1; j < remains.length; j++) {
        if (remains[j][0] == nextX) {
          cur.push(remains[j]);
          remains.splice(j, 1);
        }
      }
      cur.sort();
      var rMoves = nextX - curX;
      if (nextX > curX) {
        for (var a = 0; a < rMoves; a++) {
          path += 'R';
          curX++;
        }
      }
      for (var b in cur) {
        var uMoves = nextY - curY;
        for (var r = 0; r < uMoves; r++) {
          path += 'U';
          curY++;
        }
      }
      cur = [];
    }
    if(path.length>0){
    		print(path);
        return true;
    }else{
    	return false;
    }
  }
}

var t = +readline();
while(t--){
    var npacks = +readline();
    var packs = [];
    for (var l = 0; l < npacks; l++) {
        packs.push(readline().split(' '));
    }
    increment(npacks,packs);
}

function increment(npacks,packs){
  var curX = 0;
  var curY = 0;
  var flag = false;
  for (var i = 0; i < npacks; i++) {
    nextX = packs[i][0];
    nextY = packs[i][1];
    if (nextX < curX && nextY > curY) {
      flag = true;
    } else if (nextY < curY && nextX > curX) {
      flag = true;
    }
    curX = nextX;
    curY = nextY;
  }
  if (flag) {
    print("NO");
    return false;
  } else {
    print("YES");
    curX = 0;
    curY = 0;
    var remains = packs;
    var path = "";
    var cur = [];
    while (remains.length) {
      nextX = remains[0][0];
      nextY = remains[0][1];
      cur.push(remains[0]);
      remains.splice(0, 1);
      for (var j = 1; j < remains.length; j++) {
        if (remains[j][0] == nextX) {
          cur.push(remains[j]);
          remains.splice(j, 1);
        }
      }
      cur.sort();
      var rMoves = nextX - curX;
      if (nextX > curX) {
        for (var a = 0; a < rMoves; a++) {
          path += 'R';
          curX++;
        }
      }
      for (var b in cur) {
        var uMoves = cur[b][1] - curY;
        for (var r = 0; r < uMoves; r++) {
          path += 'U';
          curY++;
        }
      }
      cur = [];
    }
    if(path.length>0){
    		print(path);
        return true;
    }else{
    	return false;
    }
  }
}

var t = +readline();
while(t--){
    var npacks = +readline();
    var packs = [];
    for (var l = 0; l < npacks; l++) {
        packs.push(readline().split(' '));
    }
    increment(npacks,packs);
}

function increment(npacks,packs){
    packs = packs.sort(function(a,b){
       return (a[0] - b[0]);
    });
  var curX = 0;
  var curY = 0;
  var flag = false;
  for (var i = 0; i < npacks; i++) {
    nextX = packs[i][0];
    nextY = packs[i][1];
    if (nextX < curX && nextY > curY) {
      flag = true;
    } else if (nextY < curY && nextX > curX) {
      flag = true;
    }
    curX = nextX;
    curY = nextY;
  }
  if (flag) {
    print("NO");
    return false;
  } else {
    print("YES");
    curX = 0;
    curY = 0;
    var remains = packs;
    var path = "";
    var cur = [];
    while (remains.length) {
      nextX = remains[0][0];
      nextY = remains[0][1];
      cur.push(remains[0]);
      remains.splice(0, 1);
      for (var j = 1; j < remains.length; j++) {
        if (remains[j][0] == nextX) {
          cur.push(remains[j]);
          remains.splice(j, 1);
        }
      }
      cur.sort();
      var rMoves = nextX - curX;
      if (nextX > curX) {
        for (var a = 0; a < rMoves; a++) {
          path += 'R';
          curX++;
        }
      }
      for (var b in cur) {
        var uMoves = nextY - curY;
        for (var r = 0; r < uMoves; r++) {
          path += 'U';
          curY++;
        }
      }
      cur = [];
    }
    if(path.length>0){
    		print(path);
        return true;
    }else{
    	return false;
    }
  }
}

var t = +readline();
while(t--){
    var npacks = +readline();
    var packs = [];
    for (var l = 0; l < npacks; l++) {
        packs.push(readline().split(' '));
    }
    increment(npacks,packs);
}


const readline = require("readline").createInterface(process.stdin, process.stdout);
var linesLeft,
    last = '',
    result = '';
readline.on("line", line => {
  if (linesLeft === undefined)
    linesLeft = parseInt(line) * 2;
  else{
    if (linesLeft % 2 === 0)
        last = line;
    else
        solution(last, line);
    if (!(--linesLeft > 0))
        readline.close();
  }
}).on("close",() => {
  console.log(result);
  process.exit(0);
});

function solution (first, second){
    first = [...first];
    second = [...second];
    result += (first.some(ch => second.includes(ch)) ? 'yes' : 'no') + '\n';
}

const readline = require('readline');
//const lineReader = require('fs');
//const scanner = lineReader.createReadStream('main.in');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let n, lp = 0;
let x, y; //String
let frqx = new Array(27);
let frqy = new Array(27);

rl.on('line', (input) => {
    if (lp === 0){
        lp = 1;
        n = parseInt(input) * 2;
    } else if (lp === 1){
        n--;
        x = input;
        lp = 2;
    } else if (lp === 2){
        n--;
        frqx.fill(0);
        frqy.fill(0);
        lp = 1;
        y = input;
        let flg = false;
        for (let i = 0; i < x.length; i++)frqx[x.charCodeAt(i) - "a".charCodeAt(0)] += 1;
        for (let i = 0; i < y.length; i++)frqy[y.charCodeAt(i) - "a".charCodeAt(0)] += 1;
        for (let i = 0; i < 26; i++)if (frqx[i] && frqy[i]){ flg = true; break; }
        if (flg === true)console.log("YES"); else console.log("NO");
    }
    if (n === 0)rl.close();
});

const readline = require("readline").createInterface(process.stdin, process.stdout);
var linesLeft,
    last = '',
    result = '';
readline.on("line", line => {
  if (linesLeft === undefined)
    linesLeft = parseInt(line) * 2;
  else{
    if (linesLeft % 2 === 0)
        last = line;
    else
        solution(last, line);
    if (!(--linesLeft > 0))
        readline.close();
  }
}).on("close",() => {
  console.log(result)
  process.exit(0);
});

function solution (first, second){
    first = [...first];
    second = [...second];
    result += (first.some(ch => second.includes(ch)) ? 'yes' : 'no') + '\n';
}

'use strict'

readline();
let s,t;
const fn = (s, t) => {
    for (let i of s) { if (t.has(i)) return 'YES'; }
    return 'NO';
}
while((s=readline()) && (t=readline())) {
    write(fn(new Set(s.split('')), new Set(t.split(''))) + '\n');
}

n = +readline();
for (var i = 0; i < n; i++) {
    s1 = readline().split('');
    s2 = readline().split('');
    ans = 'NO';
    for (var k = 0; k < s1.length; k++) {
        if ((s2.includes(s1[k]))||(s1.includes(s2[k]))) {
            ans = 'YES';
            break;
        }
    }
    print(ans)
}

var q = readline();
for(var i = 0; i<q; i++) {
    var s = readline();
    var t = readline();
    var l = 0;

    for(var i1 = 0; i1<s.length; i1++) {
        if(t.indexOf(s.slice(i1, i1+1)) != -1) l++;
    }

    if(l===0) print('NO');
    else print('YES');
}

'use strict'

readline();
let s,t;
const fn = (s, t) => {
    for (let i of s) { if (t.has(i)) return 'YES'; }
    return 'NO';
}
while((s=readline()) && (t=readline())) {
    write(fn(new Set(s.split('')), new Set(s.split(''))));
}

'use strict'

readline();
let s,t;
const fn = (s, t) => {
    for (let i of s) { if (t.has(i)) return 'YES'; }
    return 'NO';
}
while((s=readline()) && (t=readline())) {
    write(fn(new Set(s.split('')), new Set(s.split(''))) + '\n');
}

n = +readline()
var q;
for (var i = 0; i < n;i ++){
    q = +readline();
    if (q === 1) { write(2)}
    else if (q === 2) { write(2)}
    else {
        if (q % 2 === 0){
            write(0)
        }
        else {write(1)}
    }
}

var q = readline();
var s = readline();
var t = readline();
var l = 0;
for(var i = 0; i<q; i++) {
    for(var i1 = 0; i1<q.length; i1++) {
        if(s.indexOf(q.slice(i1, i1+1) != -1)) l++
    }
   for(var i1 = 0; i1<q.length; i1++) {
        if(q.indexOf(s.slice(i1, i1+1) != -1)) l++
    }

    if(l>0) print('YES')
    else print('NO')
}