Three swimmers decided to organize a party in the swimming pool! At noon, they started to swim from the left side of the pool.It takes the first swimmer exactly $$$a$$$ minutes to swim across the entire pool and come back, exactly $$$b$$$ minutes for the second swimmer and $$$c$$$ minutes for the third. Hence, the first swimmer will be on the left side of the pool after $$$0$$$, $$$a$$$, $$$2a$$$, $$$3a$$$, ... minutes after the start time, the second one will be at $$$0$$$, $$$b$$$, $$$2b$$$, $$$3b$$$, ... minutes, and the third one will be on the left side of the pool after $$$0$$$, $$$c$$$, $$$2c$$$, $$$3c$$$, ... minutes.You came to the left side of the pool exactly $$$p$$$ minutes after they started swimming. Determine how long you have to wait before one of the swimmers arrives at the left side of the pool.

The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Next $$$t$$$ lines contains test case descriptions, one per line. Each line contains four integers $$$p$$$, $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \leq p, a, b, c \leq 10^{18}$$$), time in minutes after the start, when you came to the pool and times in minutes it take the swimmers to cross the entire pool and come back.

For each test case, output one integer — how long you have to wait (in minutes) before one of the swimmers arrives at the left side of the pool.

NoteIn the first test case, the first swimmer is on the left side in $$$0, 5, 10, 15, \ldots$$$ minutes after the start time, the second swimmer is on the left side in $$$0, 4, 8, 12, \ldots$$$ minutes after the start time, and the third swimmer is on the left side in $$$0, 8, 16, 24, \ldots$$$ minutes after the start time. You arrived at the pool in $$$9$$$ minutes after the start time and in a minute you will meet the first swimmer on the left side.In the second test case, the first swimmer is on the left side in $$$0, 6, 12, 18, \ldots$$$ minutes after the start time, the second swimmer is on the left side in $$$0, 10, 20, 30, \ldots$$$ minutes after the start time, and the third swimmer is on the left side in $$$0, 9, 18, 27, \ldots$$$ minutes after the start time. You arrived at the pool $$$2$$$ minutes after the start time and after $$$4$$$ minutes meet the first swimmer on the left side.In the third test case, you came to the pool $$$10$$$ minutes after the start time. At the same time, all three swimmers are on the left side. A rare stroke of luck!In the fourth test case, all swimmers are located on the left side in $$$0, 9, 18, 27, \ldots$$$ minutes after the start time. You arrived at the pool $$$10$$$ minutes after the start time and after $$$8$$$ minutes meet all three swimmers on the left side.

// let INPUT = `4
// 9 5 4 8
// 2 6 10 9
// 10 2 5 10
// 10 9 9 9
// `
// let INPUT_ARR = INPUT.split("\n");
// solve(INPUT_ARR.slice(1))

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL); /*your input text, split by lines*/
  solve(lines.slice(1));
});

// const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));
const bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));
// const bigIntCeil = (a) => {
//   if (a % BigInt(1) === BigInt(0)) return a;
//   return (a + BigInt(1)) % BigInt(1);
// };

function solve(lines) {
  lines.forEach((line) => {
    if (!line) return;
    const lineParsed = line.split(" ").map((e) => BigInt(e));
    const [min, a, b, c] = lineParsed;

    function calculateMin(swim) {
        if (min % swim === BigInt(0)) return BigInt(0);

      let top = (min / swim) * swim;

      while (top < min) {
        top += swim;
      }

      return top - min;
    }

    const result = bigIntMin(calculateMin(a), calculateMin(b), calculateMin(c));
    console.log(String(result));
  });
}

'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 main() {
    let t = Number(readline());
    while(t--) {
        let [p, a, b, c] = readline().split(" ").map(num => BigInt(num));
        let [ra, rb, rc] = [a, b, c];

        if(a > p) ra -= p;
        else if(a < p) ra = div(p, ra) * ra - p;

        if(b > p) rb -= p;
        else if(b < p) rb = div(p, rb) * rb - p;

        if(c > p) rc -= p;
        else if(c < p) rc = div(p, rc) * rc - p;

        if(a === p || b === p || c === p) console.log(0);
        else console.log(String(min(ra, min(rb, rc))));
    }
}

function div(dividened, quotient) {
    if(dividened % quotient === 0n) return (dividened/quotient);
    return ((dividened/quotient) + 1n);
}

function min(num1, num2) {
    let ans;
    if(num1 === num2 || num1 < num2) return num1;
    if(num2 < num1) return num2;
}

const bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);
const processData = (lines) => {
    const n = +lines[0]
    for (let i=0; i<n; i++) {
        const [p, a, b, c] = lines[i+1].split(' ').map(x => BigInt(x))
        let min = bigIntMin(p%a === 0n ? 0 : a - p%a, p%b === 0n ? 0 : b - p%b, p%c === 0n? 0 : c - p%c)
        console.log(min.toString(10))
    }
}

let i = []
process.stdin.on('data', c => i.push(c))
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.join('').split(EOL) /*your input text, split by lines*/
    processData(lines)
})

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

// Make a Snippet for the code above this and then write your logic in main();

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

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        // var х = parseInt(readline())
        // var [n, k] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        // var a = new Array(n + 1).fill(0)

        var [p, a, b, c] = readline().split(' ').map((x, iii) => {
            return BigInt(x)
        })
        var aa = (p + a - 1n) / a * a - p
        var bb = (p + b - 1n) / b * b - p
        var cc = (p + c - 1n) / c * c - p
        var min = aa < bb ? aa : bb
        min = cc < min ? cc : min
        return console.log(min.toString())
        // console.log(n, k)
        for (var i = 1; i <= n; i++) {
            count[a[i]] = Math.max(count[a[i]], i - last[a[i]])
            last[a[i]] = i
        }

        for (var i = 1; i <= n; i++) {
            var max = Math.max(count[i], n - last[i] + 1)
            for (var j = max; j <= n && ans[j] === -1; j++) {
                ans[j] = i
            }
        }

        // console.log(count)
        // console.log(a)
        console.log(ans.slice(1).join(' '))
        // console.log(map)
        // console.log(a)
    })
}

// let INPUT = `4
// 9 5 4 8
// 2 6 10 9
// 10 2 5 10
// 10 9 9 9
// `
// let INPUT_ARR = INPUT.split("\n");
// solve(INPUT_ARR.slice(1))

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL); /*your input text, split by lines*/
  solve(lines.slice(1));
});

// const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));
// const bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));
// const bigIntCeil = (a) => {
//   if (a % BigInt(1) === BigInt(0)) return a;
//   return (a + BigInt(1)) % BigInt(1);
// };

function solve(lines) {
  lines.forEach((line) => {
    if (!line) return;
    const lineParsed = line.split(" ").map((e) => Number(e));
    const [min, a, b, c] = lineParsed;

    // console.log(">", [min, a, b, c])

    // if (min % a === Number(0) || min % b === Number(0) || min % c === Number(0)) {
    //   console.log(0);
    //   return;
    // }

    // if (min === Number(0)) {
    //   console.log(Math.min(a,b,c));
    //   return;
    // }

    function calculateMin(swim) {
      return Math.ceil(min / swim) * swim - min;
    }

    const result = Math.min(calculateMin(a), calculateMin(b), calculateMin(c));
    console.log(Number(result));
  });
}

// let INPUT = `4
// 9 5 4 8
// 2 6 10 9
// 10 2 5 10
// 10 9 9 9
// `
// let INPUT_ARR = INPUT.split("\n");
// solve(INPUT_ARR.slice(1))

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL); /*your input text, split by lines*/
  solve(lines.slice(1));
});

const bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
const bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);

function solve(lines) {
  lines.forEach((line) => {
    if (!line) return;
    const lineParsed = line.split(" ").map((e) => BigInt(e));
    const [min, a, b, c] = lineParsed;

    // console.log(">", [min, a, b, c])

    if (min % a === BigInt(0) || min % b === BigInt(0) || min % c === BigInt(0)) {
        console.log(0);
        return;
    }

    if (min === BigInt(0)) {
        console.log(Number(bigIntMin(a,b,c)))
        return;
    }

    function calculateMin(swim) {
        return (swim - (min % swim)) % swim;
    }

    const result = bigIntMin(calculateMin(a), calculateMin(b), calculateMin(c));
    console.log(Number(result));
  });
}

// let INPUT = `4
// 9 5 4 8
// 2 6 10 9
// 10 2 5 10
// 10 9 9 9
// `
// let INPUT_ARR = INPUT.split("\n");
// solve(INPUT_ARR.slice(1))

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL); /*your input text, split by lines*/
  solve(lines.slice(1));
});

const bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
const bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);

function solve(lines) {
  lines.forEach((line) => {
    if (!line) return;
    const lineParsed = line.split(" ").map((e) => BigInt(e));
    const [min, a, b, c] = lineParsed;

    // console.log(">", [min, a, b, c])

    if (min % a === 0 || min % b === 0 || min % c === 0) {
        console.log(0);
        return;
    }

    if (min === BigInt(0)) {
        console.log(Number(bigIntMin(a,b,c)))
        return;
    }

    function calculateMin(swim) {
        return (swim - (min % swim)) % swim;
    }

    const result = bigIntMin(calculateMin(a), calculateMin(b), calculateMin(c));
    console.log(Number(result));
  });
}

// let INPUT = `4
// 9 5 4 8
// 2 6 10 9
// 10 2 5 10
// 10 9 9 9
// `
// let INPUT_ARR = INPUT.split("\n");
// solve(INPUT_ARR.slice(1))

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL); /*your input text, split by lines*/
  solve(lines.slice(1));
});

const bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
const bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);

function solve(lines) {
  lines.forEach((line) => {
    if (!line) return;
    const lineParsed = line.split(" ").map((e) => BigInt(e));
    const [min, a, b, c] = lineParsed;

    // console.log(">", [min, a, b, c])

    if (min == a || min == b || min == c) {
        console.log(0);
        return;
    }

    if (min === BigInt(0)) {
        console.log(Number(bigIntMin(a,b,c)))
        return;
    }

    function calculateMin(swim) {
        return (swim - (min % swim)) % swim;
    }

    const result = bigIntMin(calculateMin(a), calculateMin(b), calculateMin(c));
    console.log(Number(result));
  });
}

// let INPUT = `4
// 9 5 4 8
// 2 6 10 9
// 10 2 5 10
// 10 9 9 9
// `
// let INPUT_ARR = INPUT.split("\n");
// solve(INPUT_ARR.slice(1))

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL); /*your input text, split by lines*/
  solve(lines.slice(1));
});

const bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
const bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);

function solve(lines) {
  lines.forEach((line) => {
    if (!line) return;
    const lineParsed = line.split(" ").map((e) => BigInt(e));
    const [min, a, b, c] = lineParsed;

    // console.log(">", [min, a, b, c])

    if (min == a || min == b || min == c) {
        console.log(0);
        return;
    }

    if (min === BigInt(0)) {
        console.log(bigIntMin(a,b,c))
        return;
    }

    function calculateMin(swim) {
        return (swim - (min % swim)) % swim;
    }

    const result = bigIntMin(calculateMin(a), calculateMin(b), calculateMin(c));
    console.log(Number(result));
  });
}

// let INPUT = `4
// 9 5 4 8
// 2 6 10 9
// 10 2 5 10
// 10 9 9 9
// `
// let INPUT_ARR = INPUT.split("\n");
// solve(INPUT_ARR.slice(1))
let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL); /*your input text, split by lines*/
  solve(lines.slice(1));
});

const bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
const bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);

function solve(lines) {
  lines.forEach((line) => {
    if (!line) return;
    const lineParsed = line.split(" ").map((e) => BigInt(e));
    const [min, a, b, c] = lineParsed;

    // console.log(">", [min, a, b, c])

    if (min == a || min == b || min == c) {
        console.log(0);
        return;
    }

    if (min === 0) {
        console.log(bigIntMin(a,b,c))
        return;
    }

    function calculateMin(swim) {
        return (swim - (min % swim)) % swim;
    }

    const result = bigIntMin(calculateMin(a), calculateMin(b), calculateMin(c));
    console.log(Number(result));
  });
}

// let INPUT = `4
// 9 5 4 8
// 2 6 10 9
// 10 2 5 10
// 10 9 9 9
// `
// let INPUT_ARR = INPUT.split("\n");
// solve(INPUT_ARR.slice(1))
let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL); /*your input text, split by lines*/
  solve(lines.slice(1));
});

function solve(lines) {
  lines.forEach((line) => {
    if (!line) return;
    const lineParsed = line.split(" ").map((e) => Math.floor(e));
    const [min, a, b, c] = lineParsed;

    // console.log(">", [min, a, b, c])

    if (min == a || min == b || min == c) {
        console.log(0);
        return;
    }

    if (min === 0) {
        console.log(Math.min(a,b,c))
        return;
    }

    function calculateMin(swim) {
        return (swim - (min % swim)) % swim;
    }

    const result = Math.min(calculateMin(a), calculateMin(b), calculateMin(c));
    console.log(result);
  });
}

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL); /*your input text, split by lines*/
  solve(lines.slice(1));
});

function solve(lines) {
  lines.forEach((line) => {
    if (!line) return;
    const lineParsed = line.split(" ").map((e) => Number(e));
    const [min, a, b, c] = lineParsed;

    // console.log(">", [min, a, b, c])

    if (min == a || min == b || min == c) {
        console.log(0);
        return;
    }

    const result = Math.min((a - (min % a)), (b - (min % b)), (c - (min % c)));
    console.log(result);
  });
}

// let INPUT = `4
// 9 5 4 8
// 2 6 10 9
// 10 2 5 10
// 10 9 9 9
// `
// let INPUT_ARR = INPUT.split("\n");
// solve(INPUT_ARR.slice(1))

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL); /*your input text, split by lines*/
  solve(lines.slice(1));
});

function solve(lines) {
  lines.forEach((line) => {
    if (!line) return;
    const lineParsed = line.split(" ").map((e) => Number(e));
    const [min, a, b, c] = lineParsed;
    const result = Math.min((a - (min % a)) % a, (b - (min % b)) % b, (c - (min % c)) % c);
    console.log(result);
  });
}

// let INPUT = `4
// 9 5 4 8
// 2 6 10 9
// 10 2 5 10
// 10 9 9 9
// `
// let INPUT_ARR = INPUT.split("\n");
// solve(INPUT_ARR.slice(1))

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
    console.log(lines);

    solve(lines.slice(1))
})

function solve(lines) {

  lines.forEach(line => {
      if (!line) return;
      const lineParsed = line.split(" ").map(e => Number(e));

  const [min, a, b, c] = lineParsed

  const result = Math.min((a - min % a) % a, (b - min % b) % b, (c - min % c) % c)
  console.log(result)
  })

}

'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 main() {
    let t = Number(readline());
    while(t--) {
        let [p, a, b, c] = readline().split(" ").map(num => BigInt(num));
        let [ra, rb, rc] = [a, b, c];

        if(a > p) ra -= p;
        else if(a < p) ra = div(p, ra) * ra - p;

        if(b > p) rb -= p;
        else if(b < p) rb = div(p, rb) * rb - p;

        if(c > p) rc -= p;
        else if(c < p) rc = div(p, rc) * rc - p;

        if(a === p || b === p || c === p) console.log(0);
        else console.log(String(min(ra, min(rb, rc))));
    }
}

function div(dividened, quotient) {
    if(dividened % quotient === 0) return (dividened/quotient);
    return ((dividened/quotient) + 1n);
}

function min(num1, num2) {
    let ans;
    if(num1 === num2 || num1 < num2) return num1;
    if(num2 < num1) return num2;
}

'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 main() {
    let t = Number(readline());
    while(t--) {
        let [p, a, b, c] = readline().split(" ").map(num => BigInt(num));

        if(a > p) a -= p;
        else if(a < p) a = div(p, a) * a - p;

        if(b > p) b -= p;
        else if(b < p) b = div(p, b) * b - p;

        if(c > p) c -= p;
        else if(c < p) c = div(p, c) * c - p;

        if(a === p || b === p || c === p) console.log(0);
        else console.log(String(min(a, min(b, c))));
    }
}

function div(dividened, quotient) {
    if(dividened % quotient === 0) return (dividened/quotient);
    return ((dividened/quotient) + 1n);
}

function min(num1, num2) {
    let ans;
    if(num1 === num2 || num1 < num2) return num1;
    if(num2 < num1) return num2;
}

'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 main() {
    let t = Number(readline());
    while(t--) {
        let [p, a, b, c] = readline().split(" ").map(num => Number(num));

        if(a > p) a -= p;
        else if(a < p) a = Math.ceil(p / a) * a - p;

        if(b > p) b -= p;
        else if(b < p) b = Math.ceil(p / b) * b - p;

        if(c > p) c -= p;
        else if(c < p) c = Math.ceil(p / c) * c - p;

        if(a === p || b === p || c === p) console.log(0);
        else console.log(Math.min(a, b, c));
    }
}

'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 main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        console.log(0);
    }
}

const bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);
const processData = (lines) => {
    const n = +lines[0]
    for (let i=0; i<n; i++) {
        const [p, a, b, c] = lines[i+1].split(' ').map(x => BigInt(x))
        let min = bigIntMin(p%a === 0 ? 0 : a - p%a, p%b === 0 ? 0 : b - p%b, p%c === 0? 0 : c - p%c)
        console.log(min.toString(10))
    }
}

let i = []
process.stdin.on('data', c => i.push(c))
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.join('').split(EOL) /*your input text, split by lines*/
    processData(lines)
})

const processData = (lines) => {
    const n = +lines[0]
    for (let i=0; i<n; i++) {
        const [p, a, b, c] = lines[i+1].split(' ').map(x => +x)
        let min = Math.min(p%a === 0 ? 0 : a - p%a, p%b === 0 ? 0 : b - p%b, p%c === 0? 0 : c - p%c)
        console.log(min)
    }
}

let i = []
process.stdin.on('data', c => i.push(c))
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.join('').split(EOL) /*your input text, split by lines*/
    processData(lines)
})

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

// Make a Snippet for the code above this and then write your logic in main();

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

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        // var х = parseInt(readline())
        // var [n, k] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        // var a = new Array(n + 1).fill(0)

        var [p, a, b, c] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var aa = Math.ceil(p/a)*a - p
        var bb = Math.ceil(p/b)*b - p
        var cc = Math.ceil(p/c)*c - p
        var min = Math.min(aa, bb)
         min = Math.min(min, cc)
        return console.log(min)
        // console.log(n, k)
        for (var i = 1; i <= n; i++) {
            count[a[i]] = Math.max(count[a[i]], i - last[a[i]])
            last[a[i]] = i
        }

        for (var i = 1; i <= n; i++) {
            var max = Math.max(count[i], n - last[i] + 1)
            for (var j = max; j <= n && ans[j] === -1; j++) {
                ans[j] = i
            }
        }

        // console.log(count)
        // console.log(a)
        console.log(ans.slice(1).join(' '))
        // console.log(map)
        // console.log(a)
    })
}


British mathematician John Littlewood once said about Indian mathematician Srinivasa Ramanujan that "every positive integer was one of his personal friends."It turns out that positive integers can also be friends with each other! You are given an array $$$a$$$ of distinct positive integers. Define a subarray $$$a_i, a_{i+1}, \ldots, a_j$$$ to be a friend group if and only if there exists an integer $$$m \ge 2$$$ such that $$$a_i \bmod m = a_{i+1} \bmod m = \ldots = a_j \bmod m$$$, where $$$x \bmod y$$$ denotes the remainder when $$$x$$$ is divided by $$$y$$$.Your friend Gregor wants to know the size of the largest friend group in $$$a$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2\cdot 10^4$$$).  Each test case begins with a line containing the integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$), the size of the array $$$a$$$. The next line contains $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le {10}^{18}$$$), representing the contents of the array $$$a$$$. It is guaranteed that all the numbers in $$$a$$$ are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases is less than $$$2\cdot 10^5$$$.

Your output should consist of $$$t$$$ lines. Each line should consist of a single integer, the size of the largest friend group in $$$a$$$.

NoteIn the first test case, the array is $$$[1,5,2,4,6]$$$. The largest friend group is $$$[2,4,6]$$$, since all those numbers are congruent to $$$0$$$ modulo $$$2$$$, so $$$m=2$$$.In the second test case, the array is $$$[8,2,5,10]$$$. The largest friend group is $$$[8,2,5]$$$, since all those numbers are congruent to $$$2$$$ modulo $$$3$$$, so $$$m=3$$$.In the third case, the largest friend group is $$$[1000,2000]$$$. There are clearly many possible values of $$$m$$$ that work.

inp=require('fs').readFileSync(0).toString().split('\n'),l=0;
input=()=>inp[l++];
const log2=(i)=>31-Math.clz32(i);
const abs=(i)=>i<0?-i:i;

class sparsetable {
    constructor(vals,func) {
        this.func=func;
        let n=vals.length,p=log2(n);
        this.dp=[];
        for(let i=0;i<p+1;i++) this.dp[i]=[];
        this.dp[0]=vals;
        for (let i=1;i<=p;i++) {
            for (let j=0;j+(1<<i)<=n;j++) {
                this.dp[i][j]=func(this.dp[i-1][j],this.dp[i-1][j+(1<<(i-1))]);
            }
        }
    }
    query(l,r){
        let p=log2(r-l+1);
        return this.func(this.dp[p][l],this.dp[p][r-(1<<p)+1]);
    }
}

function gcd(a,b) {
    let g=a;
    while(b) {g=b;b=a%b;a=g;}
    return abs(g);
}

for(let t=input();t--;){
    let n=+input()-1,a=input().split(' ').map(BigInt),d=[];
    if(n==0) {console.log(1);continue;}
    for(let i=0;i<n;i++)
        d[i]=abs(a[i]-a[i+1]);
    let st=new sparsetable(d,gcd);
    let j=-1,ans=0;
    for(let i=0;i<n;i++) {
        while(j+1<n && st.query(i,j+1)>1) j++;
        if(i<=j) ans=Math.max(ans,j-i+1);
        j=Math.max(i,j);
    }
    console.log(ans+1);
}

inp=require('fs').readFileSync(0).toString().split('\n'),l=0;
input=()=>inp[l++];
const log2=(i)=>31-Math.clz32(i);

class sparsetable {
    constructor(vals,func) {
        this.func=func;
        let n=vals.length,p=log2(n);
        this.dp=[];
        for(let i=0;i<p+1;i++) this.dp[i]=[];
        this.dp[0]=vals;
        for (let i=1;i<=p;i++) {
            for (let j=0;j+(1<<i)<=n;j++) {
                this.dp[i][j]=func(this.dp[i-1][j],this.dp[i-1][j+(1<<(i-1))]);
            }
        }
    }
    query(l,r){
        let p=log2(r-l+1);
        return this.func(this.dp[p][l],this.dp[p][r-(1<<p)+1]);
    }
}

function gcd(a,b) {
    let g=a;
    while(b) {g=b;b=a%b;a=g;}
    return Math.abs(g);
}

for(let t=input();t--;){
    let n=+input()-1,a=input().split(' ').map(Number),d=[];
    if(n==0) {console.log(1);continue;}
    for(let i=0;i<n;i++)
        d[i]=Math.abs(a[i]-a[i+1]);
    let st=new sparsetable(d,gcd);
    let j=-1,ans=0;
    for(let i=0;i<n;i++) {
        while(j+1<n && st.query(i,j+1)>1) j++;
        if(i<=j) ans=Math.max(ans,j-i+1);
        j=Math.max(i,j);
    }
    console.log(ans+1);
}

inp=require('fs').readFileSync(0).toString().split('\n'),l=0;
input=()=>inp[l++];
const log2=(i)=>31-Math.clz32(i);

class sparsetable {
    constructor(vals,func) {
        this.func=func;
        let n=vals.length,p=log2(n);
        this.dp=new Array(p+1).fill(new Array(n));
        this.dp[0]=vals.slice();
        for (let i=1;i<=p;i++) {
            for (let j=0;j+(1<<i)<=n;j++) {
                this.dp[i][j]=func(this.dp[i-1][j],this.dp[i-1][j+(1<<(i-1))]);
            }
        }
    }
    query(l,r){
        let p=log2(r-l+1);
        return this.func(this.dp[p][l],this.dp[p][r-(1<<p)+1]);
    }
}

const gcd=(a,b)=>{
    let g=a;
    while(b) {g=b;b=a%b;a=g;}
    return Math.abs(g);
};

for(let t=input();t--;){
    let n=+input()-1,a=input().split(' ').map(Number),d=[];
    if(n===0) {console.log(1);continue;}
    for(let i=0;i<n;i++)
        d[i]=Math.abs(a[i+1]-a[i]);
    let st=new sparsetable(d,gcd);
    let j=-1,ans=0;
    for(let i=0;i<n;i++) {
        while(j+1<n && st.query(i,j+1)>1) j++;
        if(i<=j) ans=Math.max(ans,j-i+1);
        j=Math.max(i,j);
    }
    console.log(ans+1);
}


Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "di → ti", that means "replace all digits di in string s with substrings equal to ti". For example, if s = 123123, then query "2 → 00" transforms s to 10031003, and query "3 → " ("replace 3 by an empty string") transforms it to s = 1212. After all the queries Eugene asks Andrew to find the remainder after division of number with decimal representation equal to s by 1000000007 (109 + 7). When you represent s as a decimal number, please ignore the leading zeroes; also if s is an empty string, then it's assumed that the number equals to zero.Andrew got tired of processing Eugene's requests manually and he asked you to write a program for that. Help him!

The first line contains string s (1 ≤ |s| ≤ 105), consisting of digits — the string before processing all the requests. The second line contains a single integer n (0 ≤ n ≤ 105) — the number of queries. The next n lines contain the descriptions of the queries. The i-th query is described by string "di->ti", where di is exactly one digit (from 0 to 9), ti is a string consisting of digits (ti can be an empty string). The sum of lengths of ti for all queries doesn't exceed 105. The queries are written in the order in which they need to be performed.

Print a single integer — remainder of division of the resulting number by 1000000007 (109 + 7).

NoteNote that the leading zeroes are not removed from string s after the replacement (you can see it in the third sample).

function gao()
{

    var str = readline();
	var n   = readline();
	var opt = new Array();
	for(var i=0;i<n;i++)
	{
	    opt[i]= readline();
	}

	var len = new Array();
	var mod = new Array();

	for(var i=0;i<=9;i++)
	{
	    len[i] = 10;
	    mod[i] = i;
	}

	for(var i=n-1;i>=0;i--)
	{
		var nums = opt[i].split('->');
		var n_old = parseInt(nums[0]);
		var str_new = nums[1];
		if(str_new=='')
		{
		    len[n_old]=1;
			mod[n_old]=0;

		}
		else
		{
		    t_len = 1;
			t_mod = 0;
			for(var k=0;k<str_new.length; k++)
			{
			    var x = str_new[k];
				t_mod=( accMul(t_mod,len[x]) +mod[x] )%M;
				t_len=accMul(t_len,len[x])%M;
			}

			len[n_old] = t_len;
			mod[n_old] = t_mod;
		}
	}

	var t_len = 0;
	var t_mod = 0;

	for(var k=0;k<str.length; k++)
	{
        var x = str[k];

		t_mod = (accMul(t_mod,len[x])+mod[x])%M;
	}
	print(t_mod);

}

// test 5 fails
// due to the incorrect multiplication of js
//
function accMul(arg1,arg2)
{
   var result = 0;

   if(arg1>10000)
   {
	   var arg3 = parseInt(arg1/10000);
	   var arg4= arg1%10000;
	   result =(arg3*arg2)%M;
	   result = ((result*10000)+ arg4*arg2)%M;
   }
   else
   {
       result = (arg1*arg2)%M;
   }

   return result;
}

var p = new Array();
p[0]=1;
p[1]=10;
var M = 1000000007;
var M1 = M-1;
gao();

function gao()
{

    var str = readline();
	var n   = readline();
	var opt = new Array();
	for(var i=0;i<n;i++)
	{
	    opt[i]= readline();
	}

	// scrollable array
	var idx  = new Array();
	idx[n]  = 0;
	var len = new Array();
	var mod = new Array();

	for(var i=0;i<=9;i++)
	{
	    len[i]= new Array();
		mod[i]= new Array();
	    len[i][idx[n]] = 1;
	    mod[i][idx[n]] = i;
	}

	for(var i=n-1;i>=0;i--)
	{
	    idx[i] = 1-idx[i+1];
		var nums = opt[i].split('->');
		var n_old = parseInt(nums[0]);
		var str_new = nums[1];
		for(var j=0;j<=9;j++)
		{
		    if(j!=n_old)
			{
		        len[j][idx[i]] = len[j][idx[i+1]];
				mod[j][idx[i]] = mod[j][idx[i+1]];
			}
			else
			{
			    if(str_new =='')
				{
			        len[j][idx[i]]= 0;
				    mod[j][idx[i]]= 0;
				}
				else
				{
				    var t_len = 0;
					var t_mod = 0;
					var mm = str_new.length-1;
				    for(var k=mm;k>=0;k--)
					{
//					    var x = parseInt(str_new.charAt(k));
//                        var x = str_new.charAt(k);
                        var x = str_new[k];
                        t_mod = (t_mod + accMul(mod[x][idx[i+1]],modPower(t_len)) )%M;
						t_len = (t_len+len[x][idx[i+1]])%(M-1);

					}
					len[j][idx[i]]=t_len;
					mod[j][idx[i]]=t_mod;
				}

			}
		}
	}

	var t_len = 0;
	var t_mod = 0;

	for(var k=str.length-1;k>=0;k--)
	{
//	    var x = parseInt(str.charAt(k));
        var x = str.charAt(k);

		t_mod = (t_mod+accMul(mod[x][idx[0]],modPower(t_len)))%M;

		t_len = (t_len+len[x][idx[0]])%(M-1);
	}
	print(t_mod);

}

function  modPower(m)
{
    if(typeof(p[m])!='undefined')
	{
	    return p[m];
	}
	else
	{
	    var m1= parseInt(m/2);
		var x = modPower(m1);
		var x2 = (m1%2==1) ? 10:1;
		if(x>10000)
		{
		    var x3 = parseInt(x/10000);
			var x4 = x%10000;
			p[m] = (x3*x)%M;
			p[m] = ((p[m]*10000+x4*x)*x2)%M;
		}
		else{
		    p[m]=(x*x*x2)%M;
		}
//		var m2 = accMul(modPower(m1),modPower(m1))%(M);
//		p[m]=0;
//		if()
//		var m2 = (modPower(m1)*modPower(m1))%(M);
//		if((m&1)==1)
//		{
//		    m2= (m2*10)%(M);
//            m2= m2*10;
//		}
//		p[m]= m2;
		return p[m];
	}
}

// test 5 fails
// due to the incorrect multiplication of js
//

function accMul(arg1,arg2)
{
   var result = 0;

   if(arg1>1000000)
   {
	   var arg3 = parseInt(arg1/1000000);
	   var arg4 = arg1%1000000;
	   result =(arg3*arg2)%M;
	   result = (result*1000000+ arg4*arg2)%M;
//	   result = (arg4*arg2+result)%M;
   }
   else{
   result = (arg1*arg2)%M;
   }

   return result;
}

var p = new Array();
p[0]=1;
p[1]=10;
var M = 1000000007;
gao();

function gao()
{

    var str = readline();
	var n   = readline();
	var opt = new Array();
	for(var i=0;i<n;i++)
	{
	    opt[i]= readline();
	}

	var len = new Array();
	var mod = new Array();

	for(var i=0;i<=9;i++)
	{
	    len[i] = 1;
	    mod[i] = i;
	}

	for(var i=n-1;i>=0;i--)
	{
		var nums = opt[i].split('->');
		var n_old = parseInt(nums[0]);
		var str_new = nums[1];
		if(str_new=='')
		{
		    len[n_old]=0;
			mod[n_old]=0;

		}
		else
		{
		    t_len = 0;
			t_mod = 0;
			for(var k=0;k<str_new.length; k++)
			{
			    var x = str_new[k];
				t_mod=( t_mod*modPower(len[x])+mod[x] )%M;
				t_len=(t_len+len[x])%(M-1);
			}

			len[n_old] = t_len;
			mod[n_old] = t_mod;
		}
	}

	var t_len = 0;
	var t_mod = 0;

	for(var k=0;k<str.length; k++)
	{
        var x = str[k];

		t_mod = (t_mod*modPower(len[x])+mod[x])%M;
	}
	print(t_mod);

}

function  modPower(m)
{
    if(typeof(p[m])!='undefined')
	{
	    return p[m];
	}
	else
	{
	    if(m%2==1)
		{
		    var m1 = (m>>1);
//			p[m] = (accMul(modPower(m1),modPower(m1))*10)%M;
			p[m] = (accMul(modPower(m1),modPower(m1))*10)%M;
		}
		else
		{
		    var m1 = (m>>1);
			p[m] = accMul(modPower(m1),modPower(m1))%M;
		}

		return p[m];
	}
}

// test 5 fails
// due to the incorrect multiplication of js
//

function accMul(arg1,arg2)
{
   var result = 0;

   if(arg1>10000)
   {
//	   var arg3 = parseInt(arg1/10000);
	   var arg3 = (arg1>>10);
	   var arg4 = arg1-(arg3<<10);
	   result =(arg3*arg2)%M;
	   result = ((result*1024)+ arg4*arg2)%M;
//	   result = (arg4*arg2+result)%M;
   }
   else{
   result = (arg1*arg2)%M;
   }

   return result;
}

var p = new Array();
p[0]=1;
p[1]=10;
var M = 1000000007;
var M1 = M-1;
gao();

function gao()
{

    var str = readline();
	var n   = readline();
	var opt = new Array();
	for(var i=0;i<n;i++)
	{
	    opt[i]= readline();
	}

	// scrollable array
	var idx  = new Array();
	idx[n]  = 0;
	var len = new Array();
	var mod = new Array();

	for(var i=0;i<=9;i++)
	{
	    len[i]= new Array();
		mod[i]= new Array();
	    len[i][idx[n]] = 1;
	    mod[i][idx[n]] = i;
	}

	for(var i=n-1;i>=0;i--)
	{
	    idx[i] = 1-idx[i+1];
		var nums = opt[i].split('->');
		var n_old = parseInt(nums[0]);
		var str_new = nums[1];
		for(var j=0;j<=9;j++)
		{
		    if(j!=n_old)
			{
		        len[j][idx[i]] = len[j][idx[i+1]];
				mod[j][idx[i]] = mod[j][idx[i+1]];
			}
			else
			{
			    if(str_new =='')
				{
			        len[j][idx[i]]= 0;
				    mod[j][idx[i]]= 0;
				}
				else
				{
				    var t_len = 0;
					var t_mod = 0;
					var mm = str_new.length-1;
				    for(var k=mm;k>=0;k--)
					{
//					    var x = parseInt(str_new.charAt(k));
//                        var x = str_new.charAt(k);
                        var x = str_new[k];
                        t_mod = (t_mod + accMul(mod[x][idx[i+1]],modPower(t_len)) )%M;
						t_len = (t_len+len[x][idx[i+1]])%(M-1);

					}
					len[j][idx[i]]=t_len;
					mod[j][idx[i]]=t_mod;
				}

			}
		}
	}

	var t_len = 0;
	var t_mod = 0;

	for(var k=str.length-1;k>=0;k--)
	{
//	    var x = parseInt(str.charAt(k));
        var x = str.charAt(k);

		t_mod = (t_mod+accMul(mod[x][idx[0]],modPower(t_len)))%M;

		t_len = (t_len+len[x][idx[0]])%(M-1);
	}
	print(t_mod);

}

function  modPower(m)
{
    if(typeof(p[m])!='undefined')
	{
	    return p[m];
	}
	else
	{
	    if(m%2==1)
		{
		    var m1 = (m-1)/2;
			p[m] = (accMul(modPower(m1),modPower(m1))*10)%M;
		}
		else
		{
		    var m1 = m/2;
			p[m] = accMul(modPower(m1),modPower(m1))%M;
		}

		return p[m];
	}
}

// test 5 fails
// due to the incorrect multiplication of js
//

function accMul(arg1,arg2)
{
   var result = 0;

   if(arg1>10000)
   {
//	   var arg3 = parseInt(arg1/10000);
	   var arg4 = arg1%10000;
	   result =((arg1-arg4)*arg2)%M;
	   result = (result+ arg4*arg2)%M;
//	   result = (arg4*arg2+result)%M;
   }
   else{
   result = (arg1*arg2)%M;
   }

   return result;
}

var p = new Array();
p[0]=1;
p[1]=10;
var M = 1000000007;
gao();

function gao()
{

    var str = readline();
	var n   = readline();
	var opt = new Array();
	for(var i=0;i<n;i++)
	{
	    opt[i]= readline();
	}

	// scrollable array
	var idx  = new Array();
	idx[n]  = 0;
	var len = new Array();
	var mod = new Array();

	for(var i=0;i<=9;i++)
	{
	    len[i]= new Array();
		mod[i]= new Array();
	    len[i][idx[n]] = 1;
	    mod[i][idx[n]] = i;
	}

	for(var i=n-1;i>=0;i--)
	{
	    idx[i] = 1-idx[i+1];
		var nums = opt[i].split('->');
		var n_old = parseInt(nums[0]);
		var str_new = nums[1];
		for(var j=0;j<=9;j++)
		{
		    if(j!=n_old)
			{
		        len[j][idx[i]] = len[j][idx[i+1]];
				mod[j][idx[i]] = mod[j][idx[i+1]];
			}
			else
			{
			    if(str_new =='')
				{
			        len[j][idx[i]]= 0;
				    mod[j][idx[i]]= 0;
				}
				else
				{
				    var t_len = 0;
					var t_mod = 0;
					var mm = str_new.length-1;
				    for(var k=mm;k>=0;k--)
					{
//					    var x = parseInt(str_new.charAt(k));
//                        var x = str_new.charAt(k);
                        var x = str_new[k];
                        t_mod = (t_mod + accMul(mod[x][idx[i+1]],modPower(t_len)) )%M;
						t_len = (t_len+len[x][idx[i+1]])%(M-1);

					}
					len[j][idx[i]]=t_len;
					mod[j][idx[i]]=t_mod;
				}

			}
		}
	}

	var t_len = 0;
	var t_mod = 0;

	for(var k=str.length-1;k>=0;k--)
	{
//	    var x = parseInt(str.charAt(k));
        var x = str.charAt(k);

		t_mod = (t_mod+accMul(mod[x][idx[0]],modPower(t_len)))%M;

		t_len = (t_len+len[x][idx[0]])%(M-1);
	}
	print(t_mod);

}

function  modPower(m)
{
    if(typeof(p[m])!='undefined')
	{
	    return p[m];
	}
	else
	{
	    if(m%2==1)
		{
		    var m1 = (m-1)/2;
			p[m] = (accMul(modPower(m1),modPower(m1))*10)%M;
		}
		else
		{
		    var m1 = m/2;
			p[m] = accMul(modPower(m1),modPower(m1))%M;
		}

		return p[m];
	}
}

// test 5 fails
// due to the incorrect multiplication of js
//

function accMul(arg1,arg2)
{
   var result = 0;

//   if(arg1>10000)
    if(arg1==300133013)
   {
//	   var arg3 = parseInt(arg1/10000);
	   var arg4 = arg1%10000;
	   var arg3 = (arg1-arg4)/10000;
	   result =(arg3*arg2)%M;
	   result = (result*10000+ arg4*arg2)%M;
//	   result = (arg4*arg2+result)%M;
   }
   else{
   result = (arg1*arg2)%M;
   }

   return result;
}

var p = new Array();
p[0]=1;
p[1]=10;
var M = 1000000007;
gao();

function gao()
{

    var str = readline();
	var n   = readline();
	var opt = new Array();
	for(var i=0;i<n;i++)
	{
	    opt[i]= readline();
	}

	// scrollable array
	var idx  = new Array();
	idx[n]  = 0;
	var len = new Array();
	var mod = new Array();

	for(var i=0;i<=9;i++)
	{
	    len[i]= new Array();
		mod[i]= new Array();
	    len[i][idx[n]] = 1;
	    mod[i][idx[n]] = i;
	}

	for(var i=n-1;i>=0;i--)
	{
	    idx[i] = 1-idx[i+1];
		var nums = opt[i].split('->');
		var n_old = parseInt(nums[0]);
		var str_new = nums[1];
		for(var j=0;j<=9;j++)
		{
		    if(j!=n_old)
			{
		        len[j][idx[i]] = len[j][idx[i+1]];
				mod[j][idx[i]] = mod[j][idx[i+1]];
			}
			else
			{
			    if(str_new =='')
				{
			        len[j][idx[i]]= 0;
				    mod[j][idx[i]]= 0;
				}
				else
				{
				    var t_len = 0;
					var t_mod = 0;
				    for(var k=str_new.length-1;k>=0;k--)
					{
					    var x = parseInt(str_new.charAt(k));
						t_mod = (t_mod + mod[x][idx[i+1]]*modPower(t_len) )%M;
						t_len = (t_len+len[x][idx[i+1]])%(M-1);

					}
					len[j][idx[i]]=t_len;
					mod[j][idx[i]]=t_mod;
				}

			}
		}
	}

	var t_len = 0;
	var t_mod = 0;
//	print(str);
	for(var k=str.length-1;k>=0;k--)
	{
	    var x = parseInt(str.charAt(k));
		t_mod = (t_mod+mod[x][idx[0]]*modPower(t_len))%M;
		t_len = (t_len+len[x][idx[0]])%(M-1);
//		print('mod aaa:  '+mod[x][idx[0]]);
//		print('mod:  '+t_mod);
//		print('len:  '+t_len);
	}
	print(t_mod);

}

function  modPower(m)
{
    if(m==0)
	{
	    return 1;
	}
	else if(m==1)
	{
	    return 10;
	}
	else if(typeof(p[m])!='undefined')
	{
	    return p[m];
	}
	else
	{
	    var m1= parseInt(m/2);
		var m2 = ( modPower(m1)*modPower(m1) )%(M-1);
		if(m%2==1)
		{
		    m2= (m2*10)%(M-1);
		}
		p[m]= m2;
		return p[m];
	}
}

var p = new Array();
var M = 1000000007;
gao();


Baby Ehab is known for his love for a certain operation. He has an array $$$a$$$ of length $$$n$$$, and he decided to keep doing the following operation on it:   he picks $$$2$$$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR. Note that the length of the array decreases by one. Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $$$2$$$ elements remaining.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 15$$$) — the number of test cases you need to solve. The first line of each test case contains an integers $$$n$$$ ($$$2 \le n \le 2000$$$) — the number of elements in the array $$$a$$$. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$0 \le a_i < 2^{30}$$$) — the elements of the array $$$a$$$.

If Baby Ehab can make all elements equal while leaving at least $$$2$$$ elements standing, print "YES". Otherwise, print "NO".

NoteIn the first sample, he can remove the first $$$2$$$ elements, $$$0$$$ and $$$2$$$, and replace them by $$$0 \oplus 2=2$$$. The array will be $$$[2,2]$$$, so all the elements are equal.In the second sample, there's no way to make all the elements equal.

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function solve(n, arr) {
    let xor = 0;
    for (let i = 0; i < n; i++) {
        xor ^= arr[i];
    }
    if (xor == 0) {
        io.writeLine('YES');
        return;
    }
    let xor2 = 0;
    let count = 0;
    for (let i = 0; i < n; i++) {
        xor2 ^= arr[i];
        if (xor == xor2) {
            xor2 = 0;
            count++;
        }
    }
    io.writeLine(count > 2 ? 'YES' : 'NO');
}
function main() {
    try {
        let t = io.nextNum();
        while (t--) {
            let n = io.nextNum();
            let arr = io.nextNumArray(n);
            solve(n, arr);
        }
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    var n = parseInt(readline());
    // var [n, k] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var res = a[0]
    var met = false
    for (let j = 1; j < n ; j++) {
      res = res ^ a[j]
    }

    if (res === 0) return console.log('YES')
    var count = 0

    var aa = 0
    for (let j = 0; j < n; j++) {
      aa = a[j] ^aa
      if(aa === res) {
        count++
        aa = 0
      }
    }
    if (count>=3) return console.log('YES')
    console.log('NO')
  })
}

'use strict';

function solve(n, a) {
  const sum = a.reduce((a, b) => a ^ b, 0);
  if (sum === 0) return 'YES';
  let count = 0,
      cur = 0;
  for (let i = 0; i < n; i++) {
    cur ^= a[i];
    if (cur === sum) {
      cur = 0;
      count++;
    }
  }
  if (count >= 2) return 'YES';
  return 'NO';
}

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 dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

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

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

		let ans, req = 0;
		for (let i = 0; i < n-1; i++) {
			req ^= a[i];
			let cur = 0, found;
			for (j = i + 1; j < n; j++) {
				cur ^= a[j];
				if (cur == req) {
					found = true;
					cur = 0;
				}
			}
			ans = ans || found && cur == 0;
		}

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

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
let input = [];
rl.on('line', line => {
    input.push(line);
})
rl.on('close', line => {
    var t = Number(input[0]);
    var b = 1;
    for (var a = 0; a < t; a++) {
        var n = Number(input[b]);
        b++;
        var arr = input[b].split(" ").map((i) => {
            return Number(i);
        })
        b++;
        var total = 0;
        for (var i = 0; i < arr.length; i++) {
            total = total ^ arr[i];
        }
        if (total === 0) {
            console.log("YES")
            continue;
        }
        var sum = 0;
        var count = 0;
        for (var i = 0; i < arr.length; i++) {
            sum = sum ^ arr[i];
            if (sum === total) {
                count++;
                sum = 0;
            }
        }
        if (sum === 0 && count >= 3) {
            console.log("YES");
        } else {
            console.log("NO");
        }
    }
});

var T = parseInt(readline());

for (t = 0; t < T; t++) {
	var n = parseInt(readline());
	var a = readline().split(" ").map(x => parseInt(x));

	var ok = false;
	for (i = 0; i < n - 1; i++) {
		var re = 0;
		for (j = 0; j <= i; j++) {
			re ^= a[j];
		}
		var cur = 0;
		var once = false;
		for (j = i + 1; j < n; j++) {
			if (cur == re) { cur = 0; once = true; }
			cur ^= a[j];
		}
		if (cur == re || (once && cur == 0)) {
			ok = true;
			break;
		}
	}
	if (ok) {
		print("YES");
	} else {
		print("NO");
	}
}
/*var a = readline().split(" ").map(x => parseInt(x));

var mii = 0, mai = 0;
for (var i = 0; i < n; i++) {
	if (a[i] <= a[mii]) mii = i;
	if (a[i] > a[mai]) mai = i;
}

var ans = mai + n - mii - 1;
if (mai > mii) ans -= 1;
print(ans);*/

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function solve(n, arr) {
    arr = arr.filter((x) => x);
    while (arr.length < 2) {
        arr.push(0);
    }
    n = arr.length;
    // console.log(arr);
    if (n === 2) {
        io.writeLine(arr[0] === arr[1] ? 'YES' : 'NO');
        return;
    }
    let xor = 0;
    for (let i = 0; i < n; i++) {
        xor ^= arr[i];
    }
    // console.log({ xor, arr });
    if (xor == 0) {
        io.writeLine('YES');
        return;
    }
    let xor2 = 0;
    for (let i = 0; i < n - 1; i++) {
        xor ^= arr[i];
        if (xor == xor2) {
            io.writeLine('YES');
            return;
        }
    }
    io.writeLine('NO');
    return;
    // console.log({ arr, xor });
    // if (arr.length % 2 === 0) {
    //   io.writeLine(xor == 0 ? 'YES' : 'NO');
    //   return;
    // }
    // xor = 0;
    // for (let i = 1; i < n; i++) {
    //   xor ^= arr[i];
    // }
    // io.writeLine(xor == arr[0] ? 'YES' : 'NO');
    // return;
    let b = [];
    // if (arr.every((a) => a === arr[0])) {
    //   io.writeLine('YES');
    //   return;
    // }
    // let ret = 0;
    for (let i = 0; i < arr.length - 1;) {
        if (arr[i] !== xor) {
            arr[i] = arr[i] ^ arr[i + 1];
            arr.splice(i + 1, 1);
        }
        else {
            i++;
        }
        // ret ^= arr[i];
    }
    //console.log(arr);
    io.writeLine(arr.length > 1 && arr.every((a) => a === arr[0]) ? 'YES' : 'NO');
    // io.writeLine(ret === arr[n - 1] ? 'YES' : 'NO');
    // for (let a of arr) {
    //   ret ^= a;
    // }
    // console.log({ ret });
    // if (ret === 0) {
    //   io.writeLine('YES');
    //   return;
    // }
    // if (arr.some((a) => a === ret)) {
    //   io.writeLine('YES');
    //   return;
    // }
    // io.writeLine('NO');
}
function main() {
    try {
        let t = io.nextNum();
        while (t--) {
            let n = io.nextNum();
            let arr = io.nextNumArray(n);
            solve(n, arr);
        }
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function solve(n, arr) {
    if (n === 2) {
        io.writeLine(arr[0] === arr[1] ? 'YES' : 'NO');
        return;
    }
    let xor = 0;
    for (let i = 0; i < n; i++) {
        xor ^= arr[i];
    }
    // console.log({ xor, arr });
    if (xor == 0) {
        io.writeLine('YES');
        return;
    }
    let xor2 = 0;
    for (let i = 0; i < n - 1; i++) {
        xor ^= arr[i];
        if (xor == xor2) {
            io.writeLine('YES');
            return;
        }
    }
    io.writeLine('NO');
    return;
    // console.log({ arr, xor });
    // if (arr.length % 2 === 0) {
    //   io.writeLine(xor == 0 ? 'YES' : 'NO');
    //   return;
    // }
    // xor = 0;
    // for (let i = 1; i < n; i++) {
    //   xor ^= arr[i];
    // }
    // io.writeLine(xor == arr[0] ? 'YES' : 'NO');
    // return;
    let b = [];
    // if (arr.every((a) => a === arr[0])) {
    //   io.writeLine('YES');
    //   return;
    // }
    // let ret = 0;
    for (let i = 0; i < arr.length - 1;) {
        if (arr[i] !== xor) {
            arr[i] = arr[i] ^ arr[i + 1];
            arr.splice(i + 1, 1);
        }
        else {
            i++;
        }
        // ret ^= arr[i];
    }
    //console.log(arr);
    io.writeLine(arr.length > 1 && arr.every((a) => a === arr[0]) ? 'YES' : 'NO');
    // io.writeLine(ret === arr[n - 1] ? 'YES' : 'NO');
    // for (let a of arr) {
    //   ret ^= a;
    // }
    // console.log({ ret });
    // if (ret === 0) {
    //   io.writeLine('YES');
    //   return;
    // }
    // if (arr.some((a) => a === ret)) {
    //   io.writeLine('YES');
    //   return;
    // }
    // io.writeLine('NO');
}
function main() {
    try {
        let t = io.nextNum();
        while (t--) {
            let n = io.nextNum();
            let arr = io.nextNumArray(n);
            solve(n, arr);
        }
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function solve(n, arr) {
    let xor = 0;
    for (let i = 0; i < n; i++) {
        xor ^= arr[i];
    }
    if (xor == 0) {
        io.writeLine('YES');
        return;
    }
    let xor2 = 0;
    for (let i = 0; i < n - 1; i++) {
        xor ^= arr[i];
        if (xor == xor2) {
            io.writeLine('YES');
            return;
        }
    }
    io.writeLine('NO');
    return;
    // console.log({ arr, xor });
    // if (arr.length % 2 === 0) {
    //   io.writeLine(xor == 0 ? 'YES' : 'NO');
    //   return;
    // }
    // xor = 0;
    // for (let i = 1; i < n; i++) {
    //   xor ^= arr[i];
    // }
    // io.writeLine(xor == arr[0] ? 'YES' : 'NO');
    // return;
    let b = [];
    // if (arr.every((a) => a === arr[0])) {
    //   io.writeLine('YES');
    //   return;
    // }
    // let ret = 0;
    for (let i = 0; i < arr.length - 1;) {
        if (arr[i] !== xor) {
            arr[i] = arr[i] ^ arr[i + 1];
            arr.splice(i + 1, 1);
        }
        else {
            i++;
        }
        // ret ^= arr[i];
    }
    //console.log(arr);
    io.writeLine(arr.length > 1 && arr.every((a) => a === arr[0]) ? 'YES' : 'NO');
    // io.writeLine(ret === arr[n - 1] ? 'YES' : 'NO');
    // for (let a of arr) {
    //   ret ^= a;
    // }
    // console.log({ ret });
    // if (ret === 0) {
    //   io.writeLine('YES');
    //   return;
    // }
    // if (arr.some((a) => a === ret)) {
    //   io.writeLine('YES');
    //   return;
    // }
    // io.writeLine('NO');
}
function main() {
    try {
        let t = io.nextNum();
        while (t--) {
            let n = io.nextNum();
            let arr = io.nextNumArray(n);
            solve(n, arr);
        }
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function solve(n, arr) {
    let xor = 0;
    for (let i = 0; i < n; i++) {
        xor ^= arr[i];
    }
    let b = [];
    // if (arr.every((a) => a === arr[0])) {
    //   io.writeLine('YES');
    //   return;
    // }
    // let ret = 0;
    for (let i = 0; i < arr.length - 1;) {
        if (arr[i] !== xor) {
            arr[i] = arr[i] ^ arr[i + 1];
            arr.splice(i + 1, 1);
        }
        else {
            i++;
        }
        // ret ^= arr[i];
    }
    //console.log(arr);
    io.writeLine(arr.length > 1 && arr.every((a) => a === arr[0]) ? 'YES' : 'NO');
    // io.writeLine(ret === arr[n - 1] ? 'YES' : 'NO');
    // for (let a of arr) {
    //   ret ^= a;
    // }
    // console.log({ ret });
    // if (ret === 0) {
    //   io.writeLine('YES');
    //   return;
    // }
    // if (arr.some((a) => a === ret)) {
    //   io.writeLine('YES');
    //   return;
    // }
    // io.writeLine('NO');
}
function main() {
    try {
        let t = io.nextNum();
        while (t--) {
            let n = io.nextNum();
            let arr = io.nextNumArray(n);
            solve(n, arr);
        }
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function solve(n, arr) {
    let xor = 0;
    for (let i = 0; i < n; i++) {
        xor ^= arr[i];
    }
    let b = [];
    // if (arr.every((a) => a === arr[0])) {
    //   io.writeLine('YES');
    //   return;
    // }
    // let ret = 0;
    for (let i = 0; i < arr.length - 1;) {
        if (arr[i] !== xor) {
            arr[i] = arr[i] ^ arr[i + 1];
            arr.splice(i + 1, 1);
        }
        else {
            i++;
        }
        // ret ^= arr[i];
    }
    console.log(arr);
    io.writeLine(arr.length > 1 && arr.every((a) => a === arr[0]) ? 'YES' : 'NO');
    // io.writeLine(ret === arr[n - 1] ? 'YES' : 'NO');
    // for (let a of arr) {
    //   ret ^= a;
    // }
    // console.log({ ret });
    // if (ret === 0) {
    //   io.writeLine('YES');
    //   return;
    // }
    // if (arr.some((a) => a === ret)) {
    //   io.writeLine('YES');
    //   return;
    // }
    // io.writeLine('NO');
}
function main() {
    try {
        let t = io.nextNum();
        while (t--) {
            let n = io.nextNum();
            let arr = io.nextNumArray(n);
            solve(n, arr);
        }
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function solve(n, arr) {
    let b = [];
    // if (arr.every((a) => a === arr[0])) {
    //   io.writeLine('YES');
    //   return;
    // }
    // let ret = 0;
    for (let i = 0; i < arr.length - 1;) {
        if (arr[i] !== arr[i + 1]) {
            arr[i] = arr[i] ^ arr[i + 1];
            arr.splice(i + 1, 1);
        }
        else {
            i++;
        }
        // ret ^= arr[i];
    }
    io.writeLine(arr.every((a) => a === arr[0]) ? 'YES' : 'NO');
    // io.writeLine(ret === arr[n - 1] ? 'YES' : 'NO');
    // for (let a of arr) {
    //   ret ^= a;
    // }
    // console.log({ ret });
    // if (ret === 0) {
    //   io.writeLine('YES');
    //   return;
    // }
    // if (arr.some((a) => a === ret)) {
    //   io.writeLine('YES');
    //   return;
    // }
    // io.writeLine('NO');
}
function main() {
    try {
        let t = io.nextNum();
        while (t--) {
            let n = io.nextNum();
            let arr = io.nextNumArray(n);
            solve(n, arr);
        }
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function solve(n, arr) {
    if (arr.every((a) => a === arr[0])) {
        io.writeLine('YES');
        return;
    }
    let ret = 0;
    for (let a of arr) {
        ret ^= a;
    }
    io.writeLine(ret == 0 ? 'YES' : 'NO');
}
function main() {
    try {
        let t = io.nextNum();
        while (t--) {
            let n = io.nextNum();
            let arr = io.nextNumArray(n);
            solve(n, arr);
        }
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function solve(n, arr) {
    let ret = 0;
    for (let a of arr) {
        ret ^= a;
    }
    io.writeLine(ret == 0 ? 'YES' : 'NO');
}
function main() {
    try {
        let t = io.nextNum();
        while (t--) {
            let n = io.nextNum();
            let arr = io.nextNumArray(n);
            solve(n, arr);
        }
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    var n = parseInt(readline());
    // var [n, k] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var res = a[0]
    var met = false
    for (let j = 1; j < n ; j++) {
      res = res ^ a[j]
    }

    if (res === 0) return console.log('YES')
    var count = 0

    var aa = 0
    for (let j = 0; j < n; j++) {
      aa = a[j] ^aa
      if(aa === res) count++
    }
    if (count>=3) return console.log('YES')
    console.log('NO')
  })
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    var n = parseInt(readline());
    // var [n, k] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var res = a[0]
    var met = false
    for (let j = 1; j < n - 1; j++) {
      res = res ^ a[j]
      if (res === a[n - 1]) met = true
    }
    if (res === a[n - 1] || res === 0 && met) return console.log('YES')
    console.log('NO')
  })
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    var n = parseInt(readline());
    // var [n, k] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var res = a[0]
    for (let j = 1; j < n; j++) {
      res = res ^ a[j]
    }
    var count = 0
    if (res === 0) return console.log('YES')
    for (let j = 0; j < n; j++) {
      if (a[j] === res) count++
    }
    if (count >= 1 && n %2===1) return console.log('YES')
    return console.log('NO')

  })
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    var n = parseInt(readline());
    // var [n, k] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var res = a[0]
    for (let j = 1; j < n; j++) {
      res = res ^ a[j]
    }
    if (res === 0) return console.log('YES')
    return console.log('NO')

  })
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    var n = parseInt(readline());
    // var [n, k] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    for (let j = 0; j < n; j++) {
      var res
      res = j === 0 ? a[1] : a[0]
      for (let i = 0; i < n; i++) {
        if (i !== j) res = res ^ a[i]
      }
      if(res === a[j]) return console.log('YES')
    }
    return console.log('NO')

    console.log(a.join(' '))

  })
}

'use strict';

function solve(n, a) {
  const sum = a.reduce((a, b) => a ^ b, 0);
  if (sum === 0) return 'YES';
  const s = new Array(n);
  for (let i = 0; i < n; i++) {
    var _s;
    s[i] = ((_s = s[i - 1]) !== null && _s !== void 0 ? _s : 0) ^ a[i];
  }
  for (let i = 1; i < n - 1; i++) {
    for (let j = i; j < n - 1; j++) {
      var _s2;
      if (sum === (s[j] ^ ((_s2 = s[i - 1]) !== null && _s2 !== void 0 ? _s2 : 0))) return 'YES';
    }
  }
  return 'NO';
}

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 sum = a.reduce((a, b) => a ^ b, 0);
  if (sum === 0) return 'YES';
  const s = new Array(n);
  for (let i = 0; i < n; i++) {
    var _s;
    s[i] = ((_s = s[i - 1]) !== null && _s !== void 0 ? _s : 0) ^ a[i];
  }
  for (let i = 0; i < n; i++) {
    const N = i === 0 ? n - 1 : n;
    for (let j = i + 1; j < N; j++) {
      var _s2;
      if (sum === (s[j] ^ ((_s2 = s[i - 1]) !== null && _s2 !== void 0 ? _s2 : 0))) return 'YES';
    }
  }
  return 'NO';
}

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 dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

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

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

		let ans, req = 0;
		for (let i = 0; i < n-1; i++) {
			req ^= a[i];
			let cur = 0;
			for (j = i + 1; j < n; j++) {
				if (cur == req) cur = 0;
				cur ^= a[j];
			}
			ans = ans || req == cur;
		}

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

var T = parseInt(readline());

for (t = 0; t < T; t++) {
	var n = parseInt(readline());
	var a = readline().split(" ").map(x => parseInt(x));

	var ok = false;
	for (i = 0; i < n - 1; i++) {
		var re = 0;
		for (j = 0; j <= i; j++) {
			re ^= a[j];
		}
		var cur = 0;
		for (j = i + 1; j < n; j++) {
			if (cur == re) cur = 0;
			cur ^= a[j];
		}
		if (cur == re) {
			ok = true;
			break;
		}
	}
	if (ok) {
		print("YES");
	} else {
		print("NO");
	}
}
/*var a = readline().split(" ").map(x => parseInt(x));

var mii = 0, mai = 0;
for (var i = 0; i < n; i++) {
	if (a[i] <= a[mii]) mii = i;
	if (a[i] > a[mai]) mai = i;
}

var ans = mai + n - mii - 1;
if (mai > mii) ans -= 1;
print(ans);*/

var T = parseInt(readline());

for (t = 0; t < T; t++) {
	var n = parseInt(readline());
	var a = readline().split(" ").map(x => parseInt(x));

	var ok = false;
	for (i = 0; i < n - 1; i++) {
		var re = 0;
		for (j = 0; j <= i; j++) {
			re ^= a[j];
		}
		var cur = 0;
		for (j = i + 1; j < n; j++) {
			cur ^= a[j];
			if (cur == re) cur = 0;
		}
		if (cur == 0) {
			ok = true;
			break;
		}
	}
	if (ok) {
		print("YES");
	} else {
		print("NO");
	}
}
/*var a = readline().split(" ").map(x => parseInt(x));

var mii = 0, mai = 0;
for (var i = 0; i < n; i++) {
	if (a[i] <= a[mii]) mii = i;
	if (a[i] > a[mai]) mai = i;
}

var ans = mai + n - mii - 1;
if (mai > mii) ans -= 1;
print(ans);*/


Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel, so he can make no more than two turns on his way to his office in bank.Bankopolis looks like a grid of n rows and m columns. Igor should find a way from his home to the bank that has no more than two turns and doesn't contain cells with road works, or determine that it is impossible and he should work from home. A turn is a change in movement direction. Igor's car can only move to the left, to the right, upwards and downwards. Initially Igor can choose any direction. Igor is still sleepy, so you should help him.

The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the grid. Each of the next n lines contains m characters denoting the corresponding row of the grid. The following characters can occur:    "." — an empty cell;  "*" — a cell with road works;  "S" — the cell where Igor's home is located;  "T" — the cell where Igor's office is located.  It is guaranteed that "S" and "T" appear exactly once each.

In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.

NoteThe first sample is shown on the following picture:  In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:

  var tmp = readline().split(' ').map(x => parseInt(x));
  var n = tmp[0];
  var m = tmp[1];
  var map = [];
  for(var i = 0; i < n; i += 1) {
    map[i] = readline();
  }
  var result = false;
  var tox = [-1, 1, 0, 0];
  var toy = [0, 0, -1, 1];
  var stack = [];
  var si;
  var sj;
  var ti;
  var tj;
  var left = new Array(n + 1).fill(0).map(x => new Array(m + 1).fill(0));
  var up = new Array(n + 1).fill(0).map(x => new Array(m + 1).fill(0));
  var dfs = (ii, jj, ddir, tturn) => {
    stack.push([ii, jj, ddir, tturn]);
    while(stack.length > 0) {
      var tmp = stack.pop();
      var i = tmp[0];
      var j = tmp[1];
      var dir = tmp[2];
      var turn = tmp[3];
      if(result || turn === 2 || i < 0 || i >= n || j < 0 || j >= m || map[i][j] === '*') {
        continue;
      }
      if(j === tj) {
        if(up[ti + 1][j + 1] === up[i + 1][j + 1]) {
          result = true;
        }
      } else if(i == ti) {
        if(left[i + 1][tj + 1] - left[i + 1][j + 1] == 0) {
          result = true;
        }
      }

      stack.push([i + tox[dir], j + toy[dir], dir,  turn]);
      stack.push([i + tox[(dir + 1) % 4], j + toy[(dir + 1) % 4], (dir + 1) % 4, turn + 1]);
      stack.push([i + tox[(dir + 2) % 4], j + toy[(dir + 2) % 4], (dir + 2) % 4, turn + 1]);
      stack.push([i + tox[(dir + 3) % 4], j + toy[(dir + 3) % 4], (dir + 3) % 4, turn + 1]);
    }
  };
  for(var i = 1; i <= n; i += 1) {
    for(var j = 1; j <= m; j += 1) {
      if(map[i - 1][j - 1] === 'S') {
        si = i - 1;
        sj = j - 1;
      }
      if(map[i - 1][j - 1] === 'T') {
        ti = i - 1;
        tj = j - 1;
      }
      left[i][j] = left[i][j - 1] + (map[i - 1][j - 1] === '*' ? 1 : 0);
      up[i][j] = up[i - 1][j] + (map[i - 1][j - 1] === '*' ? 1 : 0);
    }
  }
  dfs(si, sj, 0, 0);
  dfs(si, sj, 1, 0);
  dfs(si, sj, 2, 0);
  dfs(si, sj, 3, 0);
  if(result) {
    print('YES');
  } else {
    print('NO')
  }


Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m points p1, p2, ..., pm with integer coordinates, do the following: denote its initial location by p0. First, the robot will move from p0 to p1 along one of the shortest paths between them (please notice that since the robot moves only along the grid lines, there can be several shortest paths). Then, after it reaches p1, it'll move to p2, again, choosing one of the shortest ways, then to p3, and so on, until he has visited all points in the given order. Some of the points in the sequence may coincide, in that case Robot will visit that point several times according to the sequence order.While Santa was away, someone gave a sequence of points to Robot. This sequence is now lost, but Robot saved the protocol of its unit movements. Please, find the minimum possible length of the sequence.

The first line of input contains the only positive integer n (1 ≤ n ≤ 2·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of n letters, each being equal either L, or R, or U, or D. k-th letter stands for the direction which Robot traveled the k-th unit segment in: L means that it moved to the left, R — to the right, U — to the top and D — to the bottom. Have a look at the illustrations for better explanation.

The only line of input should contain the minimum possible length of the sequence.

NoteThe illustrations to the first three tests are given below.  The last example illustrates that each point in the sequence should be counted as many times as it is presented in the sequence.

var num = readline();
var data = readline().split("");

a(num,data);

function a(num, data){
     var cnt = 1;
     var r = false; var l = false; var d = false; var u = false;
     for(i = 0; i<num; i++){
          switch(data[i]){
               case "R":
                    if(l){ var r = true; var l = false; var d = false; var u = false; cnt++; }else{ r = true; }
               break;
               case "L":
                    if(r){ var r = false; var l = true; var d = false; var u = false; cnt++; }else{ l = true; }
               break;
               case "U":
                    if(d){ var r = false; var l = false; var d = false; var u = true; cnt++; }else{ u = true; }
               break;
               case "D":
                    if(u){ var r = false; var l = false; var d = true; var u = false; cnt++; }else{ d = true; }
               break;
          }
     }
     print(cnt);
}

function sa(n, s){
        var dp = [];
        dp[0] = 0;
        var lastL = 0;
        var lastR = 0;
        var lastU = 0;
        var lastD = 0;
        for(var i=1;i<=n;i++){
            if(s[i-1] == "R"){
                lastR = i;
            } else if(s[i-1] == "L"){
                lastL = i;
            } else if(s[i-1] == "U"){
                lastU = i;
            } else if(s[i-1] == "D"){
                lastD = i;
            }
            var first = Math.min(lastL, lastR);
            var second = Math.min(lastU, lastD);
            dp[i] = dp[Math.max(first, second)] + 1;

        }
        return dp[n];
    }

    var n = Number(readline());
    var s = readline();
    print(sa(n, s));