process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', (inputStd) => {
    inputString += inputStd;
});
process.stdin.on('end', function () {
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => {
            return str.trim();
        });
    main();
});
function readLine() {
    return inputString[currentLine++];
}

function main() {
    let n = parseInt(readLine());
    let count = 0;
    for (let i = 0; i < n; i++) {
        let op = readLine();
        if (op === 'X++' || op === '++X') {
            count++;
        } else {
            count--;
        }
    }
    console.log(count);
}

readline()
  var result = 0

  var flag = true
  while (flag) {
    var line = readline()
    if (line) {
      var re = /[++]/
      re.test(line) ? result++ : result--
    } else {
      flag = false
    }
  }

  print(result)

readline()
  var result = 0

  var flag = true
  while (flag) {
    var line = readline()
    if (line) {
      var re = /[++]/
      re.test(line) ? result++ : result--
      // problems.push(line)
    } else {
      flag = false
    }
  }

  print(result)

var num=readline();
var x=0;
for(var i=0;i<num;i++){
    var cur=readline();
    cur=cur.split("X");
    if(cur[0]=="++"||cur[1]=="++"){
        x+=1;
    }else{
        x-=1;
    }
}
print(x);

var n = parseInt(readline());

var input = [];
for (var i = 1; i <= n; i++) {
    input[i] = readline();
}

var x = 0;

input.forEach(function(line){
    if (line.charAt(1) === '+') {
        x++;
    } else {
        x--;
    }
});

print(x);

var input = readline();
input = input.split(' ');

var skaicius = 0;

for(var i = 0; i < parseInt(input); i++) {
    var line = readline();

    if(line.toLowerCase() == "++x" || line.toLowerCase() == "x++") {
        skaicius++;
    } else if (line.toLowerCase() == "--x" || line.toLowerCase() == "x--") {
        skaicius--;
    }
}

print(skaicius);

var n = parseInt(readline()) || 0;

if (!(n >= 1 && n <= 150)) {
    print(0);
}
else {
    var x = 0;

    while (n-- > 0){
        var statement = readline();
        var variable = String(statement).match(/[a-zA-Z]+/)[0];
        var atBegin = statement[0] === variable;
        var symbol = atBegin ? statement[statement.length - 1] : statement[0];

        if (symbol === '+') {
            if (atBegin) x++;
            else ++x;
        } else {
            if (atBegin) x--;
            else --x;
        }
    }

    print(x);
}

var numero = readline();
var contador = 0;
for (var i = 0; i<numero;i++){
    var datos =  readline();
    if(datos=="++X" || datos=="X++"){
       contador++;
    }
    else if(datos=="--X" || datos=="X--"){
        contador--;
    }
}

print(contador);

var entrada = parseInt(readline());
var resul = 0;
var cadena;
for (var x=0 ; x<entrada; x++) {
    cadena = readline();
    if (cadena.indexOf("++")!=-1) resul++;
    else
    {
        if (cadena.indexOf("--")!=-1) resul--;
    }
}
print(resul);

var DEBUG = 0

function prt(s) {
    (DEBUG ? console.log : print)(s);
}

var a, x = 0;
function solve(line) {
    if (a === undefined) {
        a = parseInt(line);
        return true;
    }
    if (line.charAt(1) === '-') {
        x--;
    } else {
        x++;
    }
    a--;
    if (a === 0) {
        prt(x);
        return false;
    }
    return true;
}

if (DEBUG) {
    var readline = require('readline');
    var rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout,
      terminal: false
    });
    rl.on('line', function(s){solve(s)});
} else {
    while (solve(readline()));
}

/* TEST CASE
input
1
++X
output
1
input
2
X++
--X
output
0

 */
function main() {
	var n = parseInt(readline());
	var answer = 0;
	for (var i = 0; i < n; i++) {
		var s = readline();
		if (s == "++X" || s == "X++") {
			answer++;
		} else {
			answer--;
		}
	}

	print(answer);
}

main();

var n=parseInt(readline());
var x=0;
for(var i=0;i<n;i++){
    var s=readline();
    if(s==="++X"||s==="X++")
        x++;
    else
        x--
}
print(x);

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

const input = [];

function splitAndParseInt(line) {
  return line.split(" ").map((x) => parseInt(x));
}

readLine.on("line", (line) => input.push(line));
readLine.on("close", () => {
  const length = input[0];
  let x = 0;
  for(let i = 1; i <= length; i ++){
    const string = String(input[i])
    if(string.indexOf('+') != -1){
      x++;
    } else if(string.indexOf('-') != -1){
      x--;
    }
    else {
      continue;
    }
  }
  console.log(x);
});

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
var expect = 'n';
var x = 0;
rl.on('line',function(line){
    if(expect =='n'){
        n = parseInt(line);
        expect = 'statement';
        case_counter = 1;
    }else if (expect == 'statement'){
        if((line == '++X')||(line =='X++')){
            x++;
        } else {
            x--;
        }
        ++case_counter === n +1 ? rl.close() : 0;
    }
}).on('close', function(){
    console.log(x);
    process.exit(0);
});

// Generated by CoffeeScript 2.5.1
var lines, mainAux, print, readline, rl, rli, write;

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

print = console.log;

write = function(...args) {
  return process.stdout.write(args.join(' '));
};

lines = [];

rl.on('line', function(line) {
  return lines.push(line);
});

rl.on('close', main);

rli = 0;

readline = function() {
  return lines[rli++];
};

mainAux = function() {
  var i, j, numlines, ref, tot;
  numlines = readline();
  tot = 0;
  for (i = j = 1, ref = numlines; (1 <= ref ? j <= ref : j >= ref); i = 1 <= ref ? ++j : --j) {
    if (readline().includes('++')) {
      tot++;
    } else {
      tot--;
    }
  }
  return print(tot);
};

  function main() {
    return mainAux();
  }
;

//# sourceMappingURL=operator-282-a.js.map

function main() {
    const res = stdin.slice(1).reduce((s,x)=>{
        return s = (x[1] === "+") ? s+1 : s-1;
    },0)
    console.log(res)
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);});
rl.on('close', main);

var line_number = 0;
const cs = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

var lines = {};
cs.on("line", (input) => {
  if (input == "") {
    cs.close();
  }
  lines[line_number] = input.split(" ")
  line_number += 1;
}).on("close", () => {
  main();
  process.exit();
});

function isOp(str) {
  return str.length === 1 && str.match(/[<=>]/);
}
function isChr(str) {
  return str.length === 1 && str.match(/[a-z]/i);
}
function isInt(str) {
  return str.length === 1 && !isNaN(str);
}

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

function predict(test) {
  let op = "";
  let ops = [];
  let opVariables = [];
  let limits = [];
  for (let t of test) {
    // console.log(t);
    for (let i = 0; i < t.length; i++) {
      if (isOp(t[i])) {
        op = t[i];
        if (isOp(t[i + 1])) {
          op += t[i + 1];
          i += 1;
        }
        ops.push(op);
        op = "";
      } else if (isChr(t[i])) {
        // console.log(t[i])
        op = t[i];
        for (var j = i + 1; j < t.length; j++) {
          if (isChr(t[j]) || isInt(t[j])) {
            op += t[j];
            i = j;
          } else break;
        }
        opVariables.push(op);
        op = "";
      } else {
        if (i == 0 || (i > 0 && isOp(t[i - 1]))) {
          op = t[i];
          let j = i + 1;
          for (; j < t.length; j++) {
            if (isInt(t[j])) {
              op += t[j];
              i = j;
            } else break;
          }
          limits.push(op);
          op = "";
        }
      }
    }
  }

  let min = limits[0];
  let max = limits[1];

  let pvs = ops.map((o, i) => [o, opVariables[i]]);

  for (let pv of pvs) {
    if (pv[1] == undefined) {
      pv[1] = max;
    }
    // print(`${min} ${pv[0]} ${pv[1]} ?`)
    if (eval(`${min}${pv[0]}${pv[1]}`)) {
      // print(` ${min} ${pv[0]} ${pv[1]} true`)
      min = pv[1];
    } else {
      print("input error");
      process.exit();
    }
  }
}

var n
function main() {
    n = parseInt(lines[0][0], 10)
    predict(["1<=n<=150"])

    var x = 0
    for (var i = 1; i <= n; i++) {
        c = lines[i][0]
        // print(c)
        if (c[0] == '+' || c[c.length-1] == '+')
            x += 1
        else if (c[0] == "-" || c[c.length - 1] == "-")
            x -= 1;

    }

    print(x)
}

"use strict";
let input = [];
const readline=require('readline');
const RL=readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
RL.on('line', (line)=>{
  input.push(line.trim());
});
RL.on('close', ()=>{
  const n = parseInt(input[0]);
  let answer=0;
  for(let i=1; i<=n; ++i){
    if(input[i].includes("++")){
      answer++;
    } else{
      answer--;
    }
  }
  console.log(answer);
});

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

    let stdinInput = '';

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

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

    function main(data) {
      data = data.split('\n');
      const n = data.shift();
      let x = 0;
      for (let i = 0; i < n; i += 1) {
        if (data[i].match(/-/)) x -= 1;
        else x += 1;
      }
      process.stdout.write(x + '');
    }

'use strict';

const count = readline().split(/\s+/g);
const n = count[0];

let answer = 0;

for(let i=0; i<n; i++){
    const statement = readline();

    const isInc = statement.match(/\+{2}/);
    if(isInc){
        answer += 1;
        continue;
    }

    const isDec = statement.match(/\-{2}/);
    if(isDec){
        answer -= 1;
        continue;
    }
}

print(answer);

//JavaScript-C24.2.0 (SpiderMonkey)
print(interpretator(triesQuantity = readline()));
function interpretator(triesQuantity)
{
  answer = 0;
  for(; triesQuantity; triesQuantity--)
    {
        if (readline().indexOf('++') !== -1)
        {
           answer++;
        }
        else
        {
            answer--;
        }
    }
    return answer;
}

answer = 0;
for(triesQuantity = readline(); triesQuantity; triesQuantity--)
    {
        if (readline().indexOf('++') !== -1)
        {
           answer++;
        }
        else
        {
            answer--;
        }
    }
print(answer);

'use strict';

function main() {
    let n = nextInt(), ans = 0;
    while (n--) {
        let str = nextString();
        str[1] === '+' ? ++ans : --ans;
    }
    console.log(ans);
}

// ------ IO Helper ------
// nextInt(), nextFloat(), nextChar(), nextString()
// isWhitespace(charater :string), clearWhitespaces()

var input = "";
var cursor = 0;
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(data) { input += data; });
process.stdin.on('end', function() { main(); });

function isWhitespace(character) {
    return ' \t\n\r\v'.indexOf(character) > -1;
}

function clearWhitespaces() {
    while (cursor < input.length && isWhitespace(input[cursor])) ++cursor;
}

function nextInt() {
    return parseInt(nextString());
}

function nextFloat() {
    return parseFloat(nextString());
}

function nextChar() {
    clearWhitespaces();
    if (cursor < input.length)
        return input[cursor++];
    return '';
}

function nextString() {
    let str = "";
    clearWhitespaces();
    while (cursor < input.length && !isWhitespace(input[cursor])) {
        str += input[cursor++];
    }
    return str;
}

// https://codeforces.com/problemset/problem/282/A
const readline = require('readline');

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

let data = [];
rl.on('line', (input) => {
  data.push(input);
});

rl.on('close', () => {
  solve(data);
});

function solve(data) {
  let x = 0;

  for (let i = 1; i < data.length; i++) {
    const element = data[i];
    if (element.includes('++')) {
      x++;
    } else if (element.includes('--')) {
      x--;
    }
  }

  console.log(x);
}

const readline = require('readline')

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

rl.on("line", main)
let i = 0;
let n = 0;
let x = 0;
function main(input){
	if(n == 0){
		n = input
		return
	}

	if(input[0] === "X"){
		if(input[1] === "-"){
			x--
		}
		else{
			x++
		}
	}
	else{
		if(input[0] === "-"){
			x--
		}
		else{
			x++
		}
	}

	i++
	if(i === parseInt(n)){
		console.log(x)
	}

}

var t = readline();
var x = 0;
while(t--){
    var str = readline();
    if(str == '++X' || str == 'X++'){
        x++;
    }else{
        x--;
    }
}

print(x);

var n = readline();
var a;
var cnt = 0;
for(var i = 0; i < n; i++){
    a = readline();
    if(a == "++X" || a == "X++"){
        cnt++;
    }
    else{
        cnt--;
    }
}
write(cnt);

var input = ''
process.stdin.on('data', c => input += c)
process.stdin.on('end', () => {
  console.log(input.split('\r\n').slice(1,-1).reduce((a, v) => v.includes('+') ? a+1:a-1, 0))
})

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

const readLine=()=> inputString[currentLine++];
/* ================================================
           Main Solution Starts Here
===================================================*/

const main=()=>{
	let t = +readLine()
	let x=0
	while(t--){
		let operator = readLine()
		switch(operator){
			case 'X++':
				x++
				break
			case '++X':
			    ++x
			    break
			case 'X--':
				x--
				break
			case '--X':
				--x
				break
		}
	}
	console.log(x)
}

var n = readline();
var x = 0;

for(var i = 0; i < n; i++)
{
    var statement = readline();
    if(statement[0] == "+" || statement[1] == "+" || statement[2] == "+")
    {
        x++
    }
    else
    {
        x--;
    }
}

print(x);

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});

	let t = inputReader.readNumber();
	var x = 0;

	while (t--) {
	  let tmp = inputReader.readLine();
	  if (tmp[1] == "+") x++;
	  else x--;
	}

	console.log(x);

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readLine(){
		return _inputLines[_lineNumber++];
	}

	return {
		readNumber,
		readLine,
	}
}

'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 readAsInt(){
  return parseInt(readline());
}

function readAsIntList(){
  return readline().split(' ').filter(i => i).map(i => parseInt(i));
}

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

function main() {
    const n = readAsInt();
    let result = 0;
    for (let i = 0; i < n; i++) {
      result += readline().includes("++") ? 1 : -1;
    }
    console.log(result);
}

let fs = require('fs')

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter((data) => {
    return data.length > 0;
});

for (let index = 0; index < txt.length; index++) {
    if (!isNaN(txt[index]*1)) {
        let tab = []
        for (let i = 1; i <= txt[index]; i++) {
            tab.push(txt[index + i]);
        }
        square(tab)
    }

}

function square(tab) {
    let score = 0;
    tab.forEach(element => {
       if(element[0]=="+" || element[1]=="+") {
           ++score;
       }else{
           --score;
       }
    });
    console.log(score);

}

var num_lineas = readline(); // Leemos el número de lineas que debemos tratar
var sol = 0;
var linea;
// Por cada linea propuesta:
for (var i = 0; i < num_lineas; i++) {
    linea = readline(); // Leemos la linea
    // Si la linea contiene '+' sumamos 1 a la solución, en caso contrario restamos 1
    if (linea.indexOf('+') > -1) {
        sol++;
    } else {
        sol--;
    }

}
print(sol); // Imprimimos la solución

/**
 * @author Albert Hambardzumyan
 * @description Bit++.
 *  Reference: http://codeforces.com/problemset/problem/282/A
 *  Tags: implementation, 900
 */
(function () {
  const iterations = parseInt(readline())

  var x = 0
  var temp
  for (var i = 0; i < iterations; i++) {
    temp = readline()

    temp.charAt(0) === '+' || temp.charAt(2) === '+' ? x++ : x--
  }

  print(x)
})()

var n = readline()
var ans = 0

for(var i = 0; i < n; i++) {
    var exp = readline()
    if(exp[1] == "-"){
        ans--
    }else{
        ans++

    }
}
print(ans)

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline().replace(new RegExp('X' , 'g'), '')
	if(s == "++"){meghdar++}
	else{meghdar--}

}
print(meghdar)

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline();
	var k = s.indexOf("+");
	if(k == -1){meghdar--}
	else{meghdar++}

}
print(meghdar)

input=readline();
input=input.split(' ').map(e=>parseInt(e));
n=input[0]
ans=0;
while(n--){
    tmp=readline();
    ans+=(tmp.indexOf('+')===-1)?-1:1;
}
print(ans)

function main() {
    var lines = readline();
    var x = 0;
    for (; lines > 0; lines--) {
        var operation = readline();
        if (operation[1] === '+') {
            x += 1;
        } else if (operation[1] === '-') {
            x -= 1;
        }
    }
    print(x);
}
main()

var value = +readline();
var count = 0
for (var i=0; i < value; i++) {
    var c = readline().split("");
    if (c[0] === '+' || c[1] === '+' || c[2] === '+' ) {
        count++;
    } else count--
}
print(count);

const n = Number(readline());
var x = 0;
var s ;
for(var i = 0; i<n ; i++ ){
   s = readline().split("");
   if(s.includes('-')){
       x--;
   }else{
       x++;
   }
}

print(x);//

var n = readline();
var x = 0;

for (var i = 0; i < n; i++){
    var r = readline();
    if(r.includes('+')){
       x++;
    } else if (r.includes('-')){
        x--;
    }
}
print(x);

var n=readline();
var ans=0;
for (var i=0; i<n; i++){
    str=readline();
    if (str[1]=="+") ans+=1;
    if (str[1]=="-") ans-=1;
}
print (ans);

var n = Number(readline());
var ans = 0;
var str = '';

for (var i = 0 ; i < n ; i++) {
    str = readline();

    for (var j = 0 ; j < 3 ; j++) {
        if (str[j] == '+') {
            ans++;
            break;
        }
        if(str[j] == '-') {
            ans--;
            break;
        }
    }
}

print(ans);

var line=readline().split(' ');
var n=parseInt(line[0]);
var ans=0;

for(var i=0;i<n;i++){
    var f=0;
    var ip=readline().split('');
    var c='-';
    if(((ip[0]==c)&&(ip[1]==c))||((ip[2]==c)&&(ip[1]==c))){
        ans--;
    }
    else{
        ans++;
    }
}

print(ans);

var statement = Number(readline());
var x = 0;
while(statement--){
   var row = readline();

    if(row == "X++" || row == "++X"){
       x++;
    }else{
       x--;
    }

}

print(x);

var lines = readline();
var x = 0;
for (var i = 0; i < lines; i++) {
	var line = readline().split(' ');
	if (line == '++X' || line == 'X++') {
		x++;
	} else {
		x--;
	}
}
print(x);

var range = readline();
var count = 0;

for(var i=0;i<range;i++) {
    var input = readline();
    if(input.indexOf("++") > -1) {
        count++;
    } else if(input.indexOf("--") > -1) {
        count --;
    }
}

print(count);

for(var i=0,x=parseInt(readline()),c=0;i<x;i++){
c+=(readline()[1]=='+'?1:-1);
}
print(c);

n = +readline();

X = 0;

while(n--){
    eval(readline())
}
print(X)

    var lines = readline();
    var processes = [];
    var lineProcess = "";
    var x = 0;

    for(var i=0;i<lines;i++){
        lineProcess = readline();
        if(lineProcess[1]=="+"){
            x++;
        }
        else {
            x--;
        }
    };
    print(x);

var x= parseInt(readline());
var result=0;
while(x--){
  var y =readline();

  for(var i=0; i<y.length; i++){
    if(y[i] === '+'){
      result++;
      break;
    }
    if(y[i] === '-'){
      result--;
      break;
    }
  };
}

print(result);

const main = () => {
  const N = Number(readline());

  var result = 0;

  for (var i = 0; i < N; i++) {
    if (readline().indexOf("-") >= 0) {
      result--;
    } else {
      result++;
    }
  }

  return result;
};

print(main());

var cases = readline();
var res = 0;
for(var i = 0; i < cases; ++i){
    var op = readline();
    if(op.includes('--')) --res;
    if(op.includes('++')) ++res;
}

print(res);

var nOpers = readline()
var x = 0
var oper;

for(i=0;i<nOpers;i++){
	oper=readline();
	if(oper=="X++"||oper=="++X"){
		x++;
	}
	else{
		x--;
	}
}
print(x);

var n = parseInt(readline());
var x = 0;
for(var i = 0; i < n; i++){
    var w = readline();
    if(w[0] == '+' || w[1] == '+') {
        x += 1
    }else {
        x -= 1
    }
}
print(x)

var n = Number(readline());
var k=0;
for(var i=0;i<n;i++) {
var m = readline();
if ( m.indexOf('+') !== -1){
    k++;
}
else {
    k--;
}
}
print(k);

var lines = readline();
var value = 0;

for (var i = 0; i < lines; i++) {
    var targetString = readline();
    if (targetString.includes('+')) value++;
    else if (targetString.includes('-')) value--;
}

print(value);

var input = +readline();
var arrRequest = [];
var Arr = [];
var check = 0;
var x = 0;
for(var i = 0; i < input; i++){
	arrRequest[i] = readline().split('');
	Arr[i] = arrRequest[i][1];
}
Arr.forEach(function(val, index){
	if(val == '+')x++;
	if(val == '-')x--;
})
print(x);

n = readline();
number = 0 ;
for (i = 0; i < n; i++) {
    a = readline();
    if(a  == '++X' || a  == 'X++') {
       number = number + 1;
    }

    if(a  == '--X' || a  == 'X--') {
       number = number - 1;
    }

}

print(number)

var n = readline();
var a = [];

for (var i = 0; i < n; i++) {
    a.push(readline());
}

var count = 0;

a.forEach(function (j, o ,s) {
    if (j.indexOf('+') != -1) count++;
    else count--;
});

print(count);

var n = parseInt(readline());
var x = 0;
for (var i = 0; i < n; i++) {
    if (readline()[1] === "+") {
        x += 1;
    } else {
        x -= 1;
    }
}
print(x);

var n = readline();//.split(" ").map(function(x) { return parseInt(x); });
n=parseInt(n);
var arr=[];
for (var i=0;i<n;i++){
	var s = readline();
	arr.push(s);
}

var x = 0;
for(i = 0; i < arr.length; i++){
	if (arr[i] == "X++" || arr[i] =="++X"){
		x++;

	}
	if (arr[i] == "X--" || arr[i] =="--X"){
		x--;

	}

}
 print (x);

var n = readline();
var x = 0;

for (var i = 0; i < n; i++) {
    var addOrSubtract = readline()[1];
    if (addOrSubtract === '+') {
        x++;
    } else {
        x--;
    }
}
print(x);

var operations = readline();
var value = 0;
for(var i = 0; i < operations; i++) {
    if(readline().indexOf('+') !== -1) {
        value++;
    } else {
        value--;
    }
}
print(value);

var n = Math.floor(readline());
var x = 0;
for(i in n){
    w = parseInt(readline());
    if(w[0] === '+') {
        x += 1
    }else {
        x -= 1
    }
    print(x)
}

var n = Math.floor(readline());
var x = 0;
for(var i = 0; i < n; i++){
    var w = readline();
    if(w[0] === '+' || w[1] === '+') {
        x++
    }else {
        x--
    }
    print(x)
}

var n = Math.floor(readline());
for(var x = 1; x <= n; x++){
    if(x === n) {
        print(x++)
    }else {
        print(--x)
        break;

    }
}

var n = Math.floor(readline());
var x = 0;
for(i in n){
    w = parseInt(readline());
    if(w[1] === '+') {
        x += 1
    }else {
        x -= 1
    }
    print(x)
}

var n = parseInt(readline());
var x = 0;
for(var i = 0; i < n; i++){
    var w = readline();
    if(w[0] == '+' || w[1] == '+') {
        x += 1
    }else {
        x -= 1
    }
    print(x)
}

var n = Math.floor(readline());
var x = 0
for(i in n){
    w = parseInt(readline());
    if(w[1] === '+') {
        x += 1
    }else {
        x -= 1
    }
    print(x)
}

var n = Math.floor(readline());
var x = 0
for(i in n){
    w = parseInt(readline());
    if(w[0] === '+') {
        x += 1
    }else {
        x -= 1
    }
    print(x)
}

var n = Math.floor(readline());
var x = 0;
for(var i = 0; i < n; i++){
    var w = parseInt(readline());
    if(w[0] === '+' || w[1] === '+') {
        print(x++)
    }else {
        print(--x)
        break;

    }
    print(x)
}

var n = parseInt(readline());
var x = 0;
for(var i = 0; i < n; i++){
    var w = readline();
    if(w[0] == '+') {
        x++
    }else {
        x--
    }
}
print(x)

var n = Math.floor(readline());
for(var x = 0; x < n; x++){
    if(x === n) {
        print(x++)
    }else {
        print(--x)
        break;

    }
}

var countLines = readline()*1,
    x = 0;

for(var i = 0; i < countLines.length; i++){
    if(/\+/.test(readline())) x++;
    else x--;
}

print(x);

var n = readline();
var a = [];

for (var i = 0; i < n; i++) {
   a.push(readline());
}

var count = 0;

a.forEach(function (i) {
    if (i.substr(0,1) == 'X') count++;
    else count--;
});

print(count);

var n = parseInt(readline()),
	x = 0,
	s = ''

while (n > 0) {
	s = readline()
	if (s.charAt(1) == '-')
		x ++
	else
		x --
	n --
}

print(x)

var numberOfTestCases = parseInt(readline());

var input = "";

var ans = 0

for(var i = 0 ; i < numberOfTestCases ; i++) {

input = readline().split(" ");

if (input[i] == "X++" || input[i] == "++X") ans++
else ans--
}

print(ans)

var numberOfTestCases = parseInt(readline());

var input = "";

var ans = 0;

for(var i = 0 ; i < numberOfTestCases ; i++) {

input = readline();

if (input[i] == "X++" || input[i] == "++X") ans++;
else ans--;

}

print(ans);

var num_op = parseInt(readline());
var x = 0;
while(num_op >0){
    var value = readline();
    if(value == "++X" || value == "X++" ) x++;
    if(value == "--X" || value == "X--" ) x++;
    num_op--;
}
print(x);

var nOpers = parseInt(readline());
var x = 0;
var operacion;

for(var i=0;i<nOpers;i++) {
  operacion = readline();
  if(operacion == "x++" || operacion == "++x"){
    x++;
} else {
    x--;
}
}

print(x)

var nOpers = parseInt(readline());
var x = 0;
var operacion;

for(var i=0;i<nOpers;i++) {
  operacion = readline();
  if(operacion == "x++" || operacion == "++x"){
    x++;
} else if (operacion == "x--" || operacion == "--x"){
    x--;
}
}

print(x)

var nOpers = readline()
var x = 0
var oper;

for(i=0;i<nOpers;i++){
	oper=readline();
	if(oper=="x++"||oper=="++x"){
		x++;
	}
	else{
		x--;
	}
}
print(x);

var result = 0;
var nOpers = parseInt(readline());

for(i=0;i<nOpers;i++) {
  var operacion = readline();
  if(operacion == "x++" || operacion == "++x"){
    result++;
} else {
    result--;
}
}
print(result);

var a = readline() ;
while(a-- != 0){
    var str = readline() ;
    var x = 0 ;
    if(str.charAt(1) == '+')
        x++ ;
    else
        x-- ;

}
  print(x)    ;

var a = readline() ;
while(a-- != 0){
    var str = readline() ;
    var x = 0 ;
    if(str.charAt(1) == '+')
        x++ ;
    else
        x-- ;
    print(x)    ;
}

var lines = readline();
var value = 0;

for (var i = 0; i < lines; i++) {
    var targetString = readline();
    if (targetString == 'X++') value++;
    else if (targetString == '--X') value--;
}

print(value);

function main() {
    var n = readline();
    var total = 0;
    while (n--) {
        var X = readline();
        if (X[1] == '+') {
            ++total
        }
        else {
            --total
        }
    }
   console.log(total)

}

function main() {

    var n = readline();
    // var X = readline();
    var total = 0;
    while (n--) {
        // var X = readline().split('');
        var X = readline();
        if (X[1] == '+') {
            ++total
        }
        else {
            --total
        }
        // return X
    }
    return 0;
}

function main() {
    var n = readline();
    var total  = 0;
    for(var i=0;i<n;i++){
        var X = readline();
        if(X[i] == '+'){
            ++total
        }
        else{
            --total
        }

    }
    console.log(total)
}

function main() {
    var n = readline();
    var total  = 0;
    for(var i=0;i<n;i++){
        var X = readline();
        if(X[1] == '+'){
            ++total
        }
        else{
            --total
        }

    }
    console.log(total)
}

function main() {
    var n = readline();
    var total  = 0;
    for(var i=0;i<n;i++){
        var X = readline();
        if(X[i] == '+'){
            ++total
        }
        else{
            --total
        }

    }
    print(total)
}

var n = readline();
var X = 0;

for (var i = 0; i < n; i++) {
    x = readline();
}
print(X);

const main = () => {
  const x = Number(readline());
  const arr = [];
  var count = 0;

  for (var i in [...Array(x).fill()]) {
    arr.push(readline().trim());
  }

  for (var b of arr) {
    if (b === 'X++') {
      count++;
      continue;
    }
    count--;
  }

  print(count);
};

main()

'use strict';
const n = parseInt(readline());
var x = 0;

for(let i = 0; i < n; i++) {
    if(readline().indexOf('+')){
        x++;
    } else {
        x--;
    }
}

write(x);

var numero = readline();
var contador=0;
var x=0;

for (var i = 0; i<numero;i++){
    var datos =  readline().split(" ");
    if(datos[i]=="++x" || datos[i]=="x++"){
        x=+1;
    }
    if(datos[i]=="--x" || datos[i]=="x--"){
        x=-1;
    }
}
        print(x);

var numero = readline();
var contador = 0;
for (var i = 0; i<numero;i++){
    var datos =  readline().split(" ");
    if(datos[i]=="++X" || datos[i]=="X++"){
       contador++;
    }
    if(datos[i]=="--X" || datos[i]=="X--"){
        contador--;
    }
}

print(contador);

var numero = readline();
var contador=0;
var x=0;

for (var i = 0; i<numero;i++){
    var datos =  readline().split(" ");
    if(datos[i]=="++x" || datos[i]=="x++"){
        x=x+1;
    }
    if(datos[i]=="--x" || datos[i]=="x--"){
        x=x-1;
    }
}
        print(x);

var numero = readline();

var x=0;

for (var i = 0; i<numero;i++){
    var datos =  readline().split(" ");
    if(datos[i]=="++x" || datos[i]=="x++"){
       var y=1;
    }
    else if(datos[i]=="--x" || datos[i]=="x--"){
        var y= 0-1;

    }
    x=x+y;
}

print(x);

var numero = readline();
var contador = 0;
for (var i = 0; i<numero;i++){
    var datos =  readline().split(" ");
    if(datos[i]=="++x" || datos[i]=="x++"){
       contador++;
    }
    else if(datos[i]=="--x" || datos[i]=="x--"){
        contador--;
    }
}

print(contador);

var n = +readline();

var ans = 0;
for(var i = 0 ;i < n ;i++){

	var str = readline();
	if(str.charAt(1) == '+')
		ans+=1;
	else
		ans-=1;

}

var entrada = readline();
var casos = parseInt(entrada[0]);
var resul = 0;
var cadena;
var buscar = "++";
for (var x=0 ; x<casos ; x++) {
    cadena = readline();
    if (cadena.indexOf(buscar)!=-1) resul++;
    else resul--;
}
print(resul);

var entrada = readline();
var casos = parseInt(entrada[0]);
var resul = 0;
var cadena;
for (var x=0 ; x<casos ; x++) {
    cadena = readline();
    if (cadena.indexOf("++")!=-1) resul++;
    else
    {
        if (cadena.indexOf("--")!=-1) resul--;
    }
}
print(resul);

/* TEST CASE
input
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
output
word
l10n
i18n
p43s

 */
function main() {
	var n = parseInt(readline());
	for (var i = 0; i < n; i++) {
		var s = readline();
		if (s.length <= 10) {
			print(s);
		} else {
			print(s[0] + (s.length - 2) + s[s.length - 1]);
		}
	}
}

main();

var n=parseInt(readline());
var x=0;
for(var i=0;i<n;i++){
    var s=readline().split(' ');
    if(s[0]==="++X"||s[0]==="++X")
        x++;
    else
        x--
}
print(x);

var n=parseInt(readline());
var x=0;
for(var i=0;i<n;i++){
    var s=readline();
    if(s==="++X"||s==="++X")
        x++;
    else
        x--
}
print(x);

var calc = readline();

function resolve(prb) {
    var x=0;
    for (var i=0; i<prb; i++) {
        var exer = readline();
        exer=exer.toLowerCase();
        var valor,contRest, contSum = 0;
        if (exer[1]==="-") {
                contRest++;
        } else if (exer[1]==="+") {
                contSum++;
        }
        x+=contSum-contRest;
    }

    return x;
}

print (resolve(parseInt(calc)));

var loop = parseInt(readline());
var x=0;
for(var i = 0; i < loop; i++){
    var statement = readline();
    if(statement.charAt(1) == '+'){
        ++x
    }else {
        --x
    }
}

var numberOfStatements = readline();
var xValue = 0;

for(var i = 0; i < numberOfStatements; i++){
    var statement = readline();

    if(statement.indexOf('++')) xValue++;
    else if(statement.indexOf('--')) xValue--;
}

print(xValue);

var lines = readline()
var ans = 0
for(var i=0;i<lines;i++) {
    var stmt = readline()
    if(stmt.indexOf('++') === 0) {
        ans++
        continue
    }
    if(stmt.indexOf('++') > 0 && i !== lines.length) {
        ans++
        continue
    }
    if(stmt.indexOf('--') === 0) {
        ans--
        continue
    }
    if(stmt.indexOf('--') > 0 && i !== lines.length) {
        ans--
        continue
    }
}

print(ans)

var lines = parseInt(readline())
var ans = 0
for(var i=0;i<lines;i++) {
    var stmt = readline()
    if(stmt.indexOf('++') === 0) {
        ans++
        continue
    }
    if(stmt.indexOf('++') > 0 && i < lines - 1) {
        ans++
        continue
    }
    if(stmt.indexOf('--') === 0) {
        ans--
        continue
    }
    if(stmt.indexOf('--') > 0 && i < lines - 1) {
        ans--
        continue
    }
}

print(ans)

// The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.

// The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:

//     Operation ++ increases the value of variable x by 1.
//     Operation -- decreases the value of variable x by 1.

// A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.

// A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.

// You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
// Input

// The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.

// Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
// Output

// Print a single integer — the final value of x.

var n = readline();

var x = 0;
var operations = [];

var temp;
var i;
for (i = 0; i < n; i++) {
  temp = readline();
  operations.push(temp);
}

operations.forEach(function(operation) {
  if (operation === 'X++' || operation === '++X') {
    x += 1;
  } else if (operation === 'X--' || operation === '--X') {
    x -= 1;
  }
});

print(n);

// The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.

// The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:

//     Operation ++ increases the value of variable x by 1.
//     Operation -- decreases the value of variable x by 1.

// A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.

// A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.

// You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
// Input

// The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.

// Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
// Output

// Print a single integer — the final value of x.

const n = readline();

// let x = 0;
// let operations = [];

// for (let i = 0; i < n; i++) {
//   const temp = readline();
//   operations.push(temp);
// }

// operations.forEach(function(operation) {
//   if (operation === 'X++' || operation === '++X') {
//     x += 1;
//   } else if (operation === 'X--' || operation === '--X') {
//     x -= 1;
//   }
// });

print(n);

var n = parseInt(readline());
var X = 0;
var i;
for (i in n){
    eval(readline());
}
print(X);

var n = Number(readline());
var x = 0;

for (var i = 0; i < n; i++) {
    var codeLine = readline();

    if ( codeLine.indexOf('++') ) {
        x++;
    } else {
        x--;
    }
}

print( x );

var count = readline();
var num=0;
for(var i = 0; i<count; i++){
    var op = readline();
    if(count-1 == i){
       if(op === 'X++' ){
            break;
        }
        if(op === 'X--' ){
            break;
        }
    }
    if(op === '++X' || op === 'X++' ){
        ++num;
    }
    if(op === '--X' || op === 'X--' ){
        --num;
    }

}

print(num);

var linea = readline(); // Leemos el número de lineas que debemos tratar
var sol = 0;
var linea;
// Por cada linea propuesta:
for (var i = 0; i < linea; i++) {
    linea = readline(); // Leemos la linea
    // Si la linea contiene '+' sumamos 1 a la solución, en caso contrario restamos 1
    if (linea.indexOf('+') > -1) {
        sol++;
    } else {
        sol--;
    }

}
print(sol);

/**
 * @author Albert Hambardzumyan
 * @description Bit++.
 *  Reference: http://codeforces.com/problemset/problem/282/A
 *  Tags: implementation, 900
 */
(function () {
  const iterations = readline()

  var x = 0
  for (var i = 0; i < iterations; i++) {
    const temp = readline()

    temp.charAt(0) === '+' || temp.charAt(2) === '+' ? x++ : x--
  }

  print(x)
})()

var n = readline()
var ans = 0

for(var i = 0; i < n; i++) {
    var exp = readline()
    var a = (exp[0] == "-")?ans--:ans++;
}

print(ans)

var n = readline()
var ans = 0

for(var i = 0; i < n; i++) {
    var exp = readline()
    print(exp[1])
    if(exp[1] == "-"){
        ans--
    }else{
        ans++

    }

}

print(ans)

function main(){
  var n = +readline();
  var x;
  while (n>0) {
      x = readline();
        if (x.includes("++")) {
          x += +1 ;
        }
        if (x.includes("--")) {
          x += -1 ;
        }
        n--;
  }
  print(x);
}

main();

function main(){
  var n = +readline();
  var x;
  var result = 0;
  while (n>0) {
      x = readline();
        if (x.includes("++")) {
          result = +1 ;
        }
        if (x.includes("--")) {
          result = -1 ;
        }
        n--;
  }
  print(result);
}

main();

function main(){
  var n = +readline();
  var x;
  while (n>0) {
      x = readline();
        if (x.includes("++")) {
          x = x+1 ;
        }
        if (x.includes("--")) {
          x = x-1 ;
        }
        n--;
  }
  print(x);
}

main();

var n = readline();
var x = 0;

for (var i = 0; i < n; i++){
    var r = readline();
    print(r);
    if(r.includes('+')){
       x++;
    } else if (r.includes('-')){
        x--;
    }
}
print(x);

var n=readline();
var ans;
for (var i=0; i<n; i++){
    str=readline();
    if (str[1]=="+") ans++;
    if (str[1]=="-") ans--;
}
print (ans);

var n = Number(readline());
var ans = 0;
var str = '';

for (var i = 0 ; i < n ; i++) {
    str = readline();

    for (var j = 0 ; j < 3 ; j++) {
        if (str[i] == '+') {
            ans++;
            break;
        }
        else if(str[i] == '-') {
            ans--;
            break;
        }
    }
}

print(ans);

var n = Number(readline());
var ans = 0;
var str = '';

for (var i = 0 ; i < n ; i++) {
    str = readline();

    for (var j = 0 ; j < 3 ; j++) {
        if (str[i] == '+') {
            ans++;
            break;
        }
        if(str[i] == '-') {
            ans--;
            break;
        }
    }
}

print(ans);

var line=readline().split(' ');
var n=parseInt(line[0]);
var ans=0;

for(var i=0;i<n;i++){
    var f=0;
    var ip=readline().split('');
    var c='-';
    if(((ip[0]==c)&&(ip[1]==c))||((ip[2]==c)&&(ip[1]==c))){
        ans--;
    }
    else{
        ans++;
    }
    print(ans);
}

print(ans);

var lines = readline();
var x = 0;
for (var i = 0; i < lines; i++) {
	var line = readline().split(' ');
	if (line === '++X' || line === 'X++') {
		x++;
	} else {
		x--;
	}
}
print(x);

x=parseInt(readline());
var c=0;
for(var i=0;i<x;i++){
x=readline();
c+=x[1]==0;
}
print(c);

x=parseInt(readline());
var c=0;
for(var i=0;i<x;i++){
x=readline();
c+=(x[1]=='+'?1:-1);
}
print(c);

x=parseInt(readline());
var c=0;
for(var i=0;i<x;i++){
x=readline();
c+=x[1]=='+'?1:-1;
}
print(c);

x=parseInt(readline());
var c=0;
for(var i=0;i<x;i++){
x=readline();
c+=x[1]=='+';
}
print(c);

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline().replace(new RegExp('X' , 'g'), '')
	if(s = "++"){meghdar++}
	else{meghdar--}

}
print(meghdar)

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline()
	var k = s.indexOf("+");
	if(k = -1){meghdar--}
	else{meghdar++}

}
print(s)

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline()
	var k = s.indexOf("+");
	if(k = -1){meghdar--}
	else{meghdar++}

}
print(meghdar)

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline().replace(new RegExp('X' , 'g'), '')
	var k = s.indexOf("+");
	if(k = -1){meghdar--}
	else{meghdar++}

}
print(meghdar)

n = readline();
var meghdar = 0;
while(n--)
{
 	s=readline().replace(new RegExp('X' , 'g'), '')

	if(s = "++"){meghdar++}
	else{meghdar--}

}
print(meghdar)

n = readline();
var meghdar = 0;
while(n--)
{
 	s=readline().replace(new RegExp('X' , 'g'), '')

	if(s = "++"){meghdar++}
	else if(s = "--"){meghdar--}

}
print(meghdar)

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline();
	var k = s.indexOf("+");
	if(k = -1){meghdar--}
	else{meghdar++}

}
print(meghdar)

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var n=parseInt(readline());

var X=0;
for(var i=0;i<n;i++){
   if(readline()=='++X')
    X++;
    if(readline()=='--X')
    X--;
}
print(X)

var n = readline();
var X=0;
for (var i=0; i<n;i++) {
    var offer = readline();
    if (offer=='X++') X++;
    X--;
}
print(X);

var n = readline();
var X=0;
for (var i=0; i<n;i++) {
    var offer = readline();
    if (offer=='X++') {
        X++;
    } else {
        X--;
    }
}
print(X);

function main() {
    const res = stdin.reduce((s,x)=>{
        return s = x[1] === "+" ? s+1 : s-1;
    },0)
    console.log(res)
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {stdin.push(line);});
rl.on('close', main);

function main() {
    console.log(stdin);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {stdin.push(line);});
rl.on('close', main);

// var stdin = "";
// process.stdin.resume();
// process.stdin.setEncoding("ascii");
// process.stdin.on("data", function(data) {
//   stdin += data;
// });
// process.stdin.on("end", function() {
//   main(stdin);
// });

const debug = 0;
const stdin = `1

++X
`;
main(stdin);

/////////////// ignore above this line ////////////////////

function main(stdin) {
  let currentLine = 0;
  let res = 0;
  const commandCount = readLine(stdin, currentLine);

  while (commandCount > currentLine) {
    ++currentLine;
    const command = readLine(stdin, currentLine).replace("X", "");

    if (command === "++") {
      res += 1;
    } else if (command === "--") {
      res -= 1;
    }
  }

  console.log(res);
}

function readLine(str, line) {
  return str.split(/\r?\n/).filter(s => Boolean(s.trim()))[line];
}

// var stdin = "";
// process.stdin.resume();
// process.stdin.setEncoding("ascii");
// process.stdin.on("data", function(data) {
//   stdin += data;
// });
// process.stdin.on("end", function() {
//   main(stdin);
// });

const debug = 0;
const stdin = `2

X++

--X
`;
main(stdin);

/////////////// ignore above this line ////////////////////

function main(stdin) {
  let currentLine = 0;
  let res = 0;
  const commandCount = readLine(stdin, currentLine);

  while (commandCount > currentLine) {
    ++currentLine;
    const command = readLine(stdin, currentLine).replace("X", "");

    if (command === "++") {
      res += 1;
    } else if (command === "--") {
      res -= 1;
    }
  }

  console.log(res);
}

function readLine(str, line) {
  return str.split("\n").filter(s => Boolean(s.trim()))[line];
}

var stdin = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function(data) {
  stdin += data;
});
process.stdin.on("end", function() {
  main(stdin);
});

// main(stdin);

/////////////// ignore above this line ////////////////////

function main(stdin) {
  let currentLine = 0;
  let res = 0;
  const commandCount = readLine(stdin, currentLine);

  while (commandCount > currentLine) {
    ++currentLine;
    const command = readLine(stdin, currentLine).replace("X", "");

    if (command === "++") {
      res += 1;
    } else if (command === "--") {
      res -= 1;
    }
  }

  console.log(res);
}

function readLine(str, line) {
  return str.split("\n")[line];
}

// var stdin = "";
// process.stdin.resume();
// process.stdin.setEncoding("ascii");
// process.stdin.on("data", function(data) {
//   stdin += data;
// });
// process.stdin.on("end", function() {
//   main(stdin);
// });

const debug = 0;
const stdin = `1

++X
`;
main(stdin);

/////////////// ignore above this line ////////////////////

function main(stdin) {
  let currentLine = 0;
  let res = 0;
  const commandCount = readLine(stdin, currentLine);

  while (commandCount > currentLine) {
    ++currentLine;
    const command = readLine(stdin, currentLine).replace("X", "");

    if (command === "++") {
      res += 1;
    } else if (command === "--") {
      res -= 1;
    }
  }

  console.log(res);
}

function readLine(str, line) {
  return str.split("\n").filter(Boolean)[line];
}

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

let first = true;
let total = 0;
rl.on('line', line => {
    if (first === true) {
        total = parseInt(line);
        first = false;
    }
    input = line;
    solution(input, total);
});

rl.on('close', () => {
    console.log(total);
});

function solution(input) {
    const operator = input[1];

    if (operator === '+') {
        total += 1;
    } else if (operator === '-') {
        total -= 1;
    }
}

'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(s){
    process.stdout.write(s);
}

function println(s){
    console.log(s);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    // var n = readline().split(' ');
    // for(var i=0; i<a.length; i++){
    //     println(a[i]);
    // }

    // var b = parseInt(a[0])/parseInt(a[1]);
    // println(String(b));

    var n = parseInt(readline().split(' ')[0]);
    println(n);

    var x  = 0;
    for(var i=0; i<n; i++){
        var op = readline().split(' ')[0];
        if(op == "X++" || op == "++X"){
            x++;
        }else{
            x--;
        }
    }

    println(x);
}

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

// read each line
let i = 0;
let arr = [];
rl.on("line", (lineInput) => {
  if (i !== 1) arr.push(lineInput);
  i++;
});

// when all file readed
rl.on("close", () => {
  let result = 0;
  for (let index = 0; index < arr.length; index++) {
    if (arr[index].indexOf("++") > -1) result++;
    if (arr[index].indexOf("--") > -1) result--;
  }
  console.log(result);
});

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

// read each line
let i = 0;
let arr = [];
rl.on("line", (lineInput) => {
  if (i !== 1) arr.push(lineInput);
  i++;
});

// when all file readed
rl.on("close", () => {
  let result = 0;
  arr.forEach(function (el) {
    if (el.indexOf("++") > -1) result++;
    if (el.indexOf("--") > -1) result--;
  });
  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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let n = parseInt(readLine());
    let arr = [];
    let ans = 0;
    for (let i = 0; i < n; i++) {
        arr.push(readLine());
        if (arr[0].indexOf('-') != -1) {
            ans--;
        } else ans++;
    }
    console.log(ans);
}


'use-strict'

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

let data = '';
let currentLine = 0;

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

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

    const [n, queries] = readLine().split(' ').map(Number);

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

    const colors = readLine().split(' ').map(Number); //query colors.

    c(n,queries,arr,colors)

});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function c(n,q,a,t)
{
    const N = 60;

    let pos = Array(N).fill(-1);
    for (let i = 0; i < n; i++) {
        if (pos[a[i]] < 0) pos[a[i]] = i;
    }
    let res = [];
    for (let k = 0; k < q; k++) {
        res.push(pos[t[k]] + 1);
        for (let i = 1; i < 60; i++) {
            if (pos[i] >= 0 && pos[i] < pos[t[k]]) {
                pos[i]++;
            }
        }
        pos[t[k]] = 0;
    }
    return console.log(res.join(' '))
}

module.exports = c;

"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++];
}
class Node {
  constructor(val) {
    this.val = val;
    this.next = null;
    this.prev = null;
  }
}
class Dl {
  constructor() {
    this.head = null;
    this.tail = null;
  }
  push(val) {
    if (!this.head) this.head = this.tail = new Node(val);
    else {
      let newn = new Node(val);
      this.tail.next = newn;
      newn.prev = this.tail;
      this.tail = newn;
    }
  }
  shift(val) {
    let newN = new Node(val);
    newN.next = this.head;
    this.head.prev = newN;
    this.head = newN;
  }
  remove(val) {
    let ind = 1,
      p = this.head;
    while (p) {
      if (p.val === val) {
        if (p.prev === null) return ind;
        else if (p.next === null) {
          this.shift(p.val);
          this.tail = p.prev;
          this.tail.next = null;
          return ind;
        } else {
          this.shift(p.val);
          p.prev.next = p.next;
          p.next.prev = p.prev;
          return ind;
        }
      }
      p = p.next;
      ind++;
    }
  }
}
const solve = () => {
  let t = 1;
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let q = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let list = new Dl();
    for (let i = 0; i < n; i++) list.push(arr[i]);
    let res = "";
    for (let i = 0; i < k; i++) res += list.remove(q[i]) + " ";
    console.log(res);
  }
};
solve();

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 set = new Array(51).fill(Infinity); // index is card number, value is highest position.
    var a = input[1].split(" ").map((i) => {
        return Number(i);
    });
    var query = input[2].split(" ").map((i) => {
        return Number(i);
    });
    for (let i = 0; i < a.length; i++) {
        set[a[i]] = Math.min(i + 1, set[a[i]]);
    }
    var result = [];
    for (let i = 0; i < query.length; i++) {
        var index = set[query[i]];
        result.push(index);
        for (var j = 1; j <= 50; j++) {
            if (set[j] < index) {
                set[j] += 1;
            }
        }
        set[query[i]] = 1;
    }
    console.log(result.join(" "));
})

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

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

function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  //   var n = parseInt(readline());
  var [n, qq] = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  })
  // var [x, y] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // });
  var a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  })
  var q = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  })
  var colors = new Array(51)
  for (let j = 0; j < 51; j++) {
    colors[j] = -1
  }

  for (let j = 0; j < a.length; j++) {
    if (colors[a[j]] === -1) colors[a[j]] = j
  }
  var res = ''
  for (let i = 0; i < q.length; i++) {
    res = res + (colors[q[i]]+1) + ' '
    for (let j = 0; j < 51; j++) {
      if (colors[j] < colors[q[i]] && colors[j] !== -1) colors[j] += 1
    }
    colors[q[i]] = 0
  }
  console.log(res)

  // })
}

'use-strict'

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

let data = '';
let currentLine = 0;

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

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

    const [n, queries] = readLine().split(' ').map(Number);

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

    const colors = readLine().split(' ').map(Number); //query colors.

    c(n,queries,arr,colors)

});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function c(n,q,a,t)
{
    const N = 50;

    let pos = Array(N).fill(-1);
    for (let i = 0; i < n; i++) {
        if (pos[a[i]] < 0) pos[a[i]] = i;
    }
    let res = [];
    for (let k = 0; k < q; k++) {
        res.push(pos[t[k]] + 1);
        for (let i = 1; i < 60; i++) {
            if (pos[i] >= 0 && pos[i] < pos[t[k]]) {
                pos[i]++;
            }
        }
        pos[t[k]] = 0;
    }
    return console.log(res.join(' '))
}

module.exports = c;

'use-strict'

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

let data = '';
let currentLine = 0;

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

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

    const [n, queries] = readLine().split(' ').map(Number);

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

    const colors = readLine().split(' ').map(Number); //query colors.

    c(n,queries,arr,colors)

});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function c(n,q,a,t)
{
    const N = 50;

    let pos = Array(N).fill(-1);
    for (let i = 0; i < n; i++) {
        if (pos[a[i]] < 0) pos[a[i]] = i;
    }
    let res = [];
    for (let k = 0; k < q; k++) {
        res.push(pos[t[k]] + 1);
        for (let i = 1; i < 51; i++) {
            if (pos[i] >= 0 && pos[i] < pos[t[k]]) {
                pos[i]++;
            }
        }
        pos[t[k]] = 0;
    }
    return console.log(res.join(' '))
}

module.exports = c;

'use-strict'

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

let data = '';
let currentLine = 0;

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

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

        let [n,q] = get_ints();
        let a = get_ints();
        let c = get_ints();
        let ans = [];
        var idx = 0;
        for(let i = 0 ;  i < q; i++)
        {
            let a_new = [];
            const color = c[i];
            for(let j = 0 ; j < n; j++)
            {
                if(a[j] === color)
                {
                   a_new.unshift(color)
                   ans.push(j+1);
                   //console.log('a_new = ', a_new, 'a.slice(j+1) = ', a.slice(j+1))
                   //print(a_new.concat(a.slice(j+1)))
                   idx = j;
                   break;
                }
                else
                {
                    a_new.push(a[j])
                }
            }
            a = a_new.concat(a.slice(idx+1));
        }
        print(ans);
});

function print(c){
    return console.log(c);
}

function get_ints() {
    return readLine().split(' ').map(Number);
}

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

"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++];
}
class Node {
  constructor(val) {
    this.val = val;
    this.next = null;
    this.prev = null;
  }
}
class Dl {
  constructor() {
    this.head = null;
    this.tail = null;
  }
  push(val) {
    if (!this.head) this.head = this.tail = new Node(val);
    else {
      let newn = new Node(val);
      newn.prev = this.tail;
      this.tail = this.tail.next = newn;
    }
  }
  shift(val) {
    let newN = new Node(val);
    newN.next = this.head;
    this.head = newN;
  }
  remove(val) {
    let ind = 1,
      p = this.head;
    while (p) {
      if (p.val === val) {
        if (p.prev === null) return ind;
        else if (p.next === null) {
          this.shift(p.val);
          p.prev = null;
          this.tail = p.prev;
          return ind;
        } else {
          this.shift(p.val);
          p.prev.next = p.next;
          p.next.prev = p.prev;
          return ind;
        }
        break;
      }
      p = p.next;
      ind++;
    }
  }
}
const solve = () => {
  let t = 1;
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let q = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let list = new Dl();
    for (let i = 0; i < n; i++) list.push(arr[i]);
    let res = "";
    for (let i = 0; i < k; i++) res += list.remove(q[i]) + " ";
    console.log(res);
  }
};
solve();


var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseArray = readline().split(" ");
    var l1 = parseInt(caseArray[0]);
    var r1 = parseInt(caseArray[1]);
    var l2 = parseInt(caseArray[2]);
    var r2 = parseInt(caseArray[3]);
    var result = l1;
    if (l1 < l2)
    {
        if (r1 >= l2)
        {
            result = l2;
        }
        else
        {
            result = l1 + l2;
        }
    }
    if (l1 > l2)
    {
        if (l1 <= r2)
        {
            result = l1;
        }
        else
        {
            result = l1 + l2;
        }
    }
    print(result);
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var a = lines[i].split(' ').map(Number);
        var l1 = a[0], r1 = a[1], l2 = a[2], r2 = a[3];
        if(Math.max(l1, l2) <= Math.min(r1, r2)){
            console.log(Math.max(l1, l2));
        }else{
            console.log(l1 + l2);
        }
    }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let [l1, r1, l2, r2] = readline().split(' ').map(Number);

        if (r1 < l2 || r2 < l1) {
            output(l1 + l2);
        } else {
            output(Math.max(l1, l2));
        }
    }
}

let text = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', str => {
    if (str === '\r\n' || str === '\n') {
        process.stdin.emit('end');
    } else {
        text += str;
    }
});

process.stdin.on('end', () => {
    const input = text.trim().replace(/\r/g, '').split('\n');
    const total = +input[0];

    for (let i = 1; i <= total; i++) {
        console.log(solve(input[i]));
    }

    process.exit();
});

function solve(str) {
    let [l1, r1, l2, r2] = str.split(' ').map(ele => +ele);
    if (r1 >= l2 && l1 <= r2) {
        return Math.max(l1, l2);
    }
    return l1 + l2;
}

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

function solve(arr) {
    const [a, b, c, d] = arr
    if (a > c) return solve([c, d, a, b])
    if (c <= b) {
        return c
    } else {
        return a + c
    }
}

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let [inputString, currentLine] = ['', 0];
process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
});
const input = () => inputString[currentLine++];

const main = () => {
  let tc = parseInt(input());
  while(tc--){
    const a = Array(51).fill(0);
    const [l1, r1, l2, r2] = input().split(' ').map(Number);
    for(let i = l1; i <= r1; i++){
      a[i] += 1;
    }
    for(let i = l2; i <= r2; i++){
      a[i] += 1;
    }
    let two = false;
    for(let i = 1; i < 51; i++){
      if(a[i] === 2) two = true;
    }
    let ans = l1+l2;
    if(two){
      for(let i = 1; i < 51; i++){
        if(a[i] === 2){
          ans = Math.min(ans, i);
          break;
        }
      }
    }
    console.log(ans);
  }
}

'use strict';

var readline = require('readline');

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

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

function solve(a) {
  const [l1, r1, l2, r2] = a;
  if (l1 <= l2) {
    if (r1 >= l2) {
      return l2;
    } else {
      return l1 + l2;
    }
  } else {
    if (l1 <= r2) {
      return l1;
    } else {
      return l1 + l2;
    }
  }
}

async function main(read) {
  let t = Number(await read());
  let res = [];
  while (t--) {
    const a = (await read()).split(' ').map(Number);
    res.push(solve(a));
  }
  console.log(res.join('\n'));
}

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

'use strict';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T);
  } else
   pcalc();
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`Test #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [l1, r1, l2, r2] = ra();
  LT({l1, r1, l2, r2})
  for (let i=1; i<=100; i++){
    for (let j=0; j<=i; j++){
      let min_cnt = j;
      let max_cnt = i-j;
      if (j==0){
        min_cnt = i;
        max_cnt = i;
      }
      if (l1<=min_cnt && min_cnt<=r1)
        if (l2<=max_cnt && max_cnt<=r2)
          return i;
    }
  }
  throw 'error';
};

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

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

/*---------------------------------------------------*/

const calc = ()=>{
    /* read */
    let [l1, r1, l2, r2] = ra();

    /* solve */
    let result = 0;

    if (l1 <= l2 && l2 <= r1) {
        return l2;
    }
    if (l2 <= l1 && l1 <= r2) {
        return l1;
    }

    return l1 + l2;
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc());
        // process.stdout.write(`${calc(n, a)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

var t = +readline();

for(var i = 0; i< t; i ++) {
    var a = readline().split(' ').map((t) => +t);

    print(Task1(a));

}

function Task1(arr){

  var l1 = arr[0];
  var r1 = arr[1];
  var l2 = arr[2];
  var r2 = arr[3];
  var res = l1 + l2;
  if (l1 <= l2 && l2 <= r1) res = l2;
  if (l2 <= l1 && l1 <= r2) res = l1;
  return res;

}

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
while (t--) {
    var _a = readline().split(' ').map(function (v) { return +v; }), l1 = _a[0], r1 = _a[1], l2 = _a[2], r2 = _a[3];
    var ans = void 0;
    if (r1 >= l2 && r2 >= l1) {
        ans = Math.max(l1, l2);
    }
    else {
        ans = l1 + l2;
    }
    print(ans);
}

let ryan = '';//.map(Numaer).sort(function(a, a){return a - a})
process.stdin.on('data', c => ryan += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = ryan.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j++){
        var k = lines[j].split(' ').map(Number), a = k[0], b = k[1], c = k[2], d = k[3]

        if(Math.max(a, c) <= Math.min(b, d)){
            console.log(Math.max(a, c));
        }else{
            console.log(a + 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++];
}

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();
    //
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        var [u, v] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        if (u > v) return console.log('NO')

        var ans = true
        var count = 0

        for (let i = 0; i < 40; i++) {
            if (u >> i & 1) count++

            if (v >> i & 1) {
                if(count<=0) ans = false
                count--
            }
        }
        console.log(ans?'YES':'NO')

    })
}

function checkString(a) {
    // console.log(a)
    var count = 0
    var res = true
    for (let i = 0; i < a.length; i++) {
        if (a[i] === '(') count++
        else {
            count--
            if (count < 0) res = false
        }
    }
    if (count !== 0) res = false

    return res

}

'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 = () => Number(read());
  let u = rn(),
      v = rn();
  if (u > v) return 'NO';
  if (u === v) return 'YES';
  if (u % 2 === 0 && v % 2 === 1) return 'NO';
  const count = num => {
    let cnt = 0;
    while (num) {
      cnt++;
      num -= num & -num;
    }
    return cnt;
  };
  if (count(u) < count(v)) return 'NO';
  let a = 0,
      b = 0;
  for (let i = 0; i < 32; i++) {
    if (1 << i > v) break;
    if (v & 1 << i) a++;
    if (u & 1 << i) b++;
    if (a > b) return 'NO';
  }
  return 'YES';
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = 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 = () => Number(read());
  let u = rn(),
      v = rn();
  if (u > v) return 'NO';
  if (u === v) return 'YES';
  if (u % 2 === 0 && v % 2 === 1) return 'NO';
  const count = num => {
    let cnt = 0;
    while (num) {
      cnt++;
      num -= num & -num;
    }
    return cnt;
  };
  if (count(u) < count(v)) return 'NO';
  while (u) {
    if (v & 1 && !(u & 1)) return 'NO';
    v >>= 1;
    u >>= 1;
  }
  return 'YES';
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = 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 = () => Number(read());
  const u = rn(),
        v = rn();
  if (u > v) return 'NO';
  if (u === v) return 'YES';
  if (u % 2 === 0 && v % 2 === 1) return 'NO';
  const count = num => {
    let cnt = 0;
    while (num) {
      cnt++;
      num -= num & -num;
    }
    return cnt;
  };
  if (count(u) < count(v)) return 'NO';
  return 'YES';
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'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();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();
    //
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        var [u, v] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        if (u > v) return console.log('NO')

        var ans = true
        var count = 0

        for (let i = 0; i < 40; i++) {
            if (u >> i & 1) count++

            if (v >> i & 1) {
                if(count<0) {
                    ans = false
                    break
                }
                count--
            }
        }
        console.log(ans?'YES':'NO')

    })
}

function checkString(a) {
    // console.log(a)
    var count = 0
    var res = true
    for (let i = 0; i < a.length; i++) {
        if (a[i] === '(') count++
        else {
            count--
            if (count < 0) res = false
        }
    }
    if (count !== 0) res = false

    return res

}

'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();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();
    //
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        var [u, v] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        if (u > v) return console.log('NO')

        var ans = true
        var count = 0

        for (let i = 0; i < 40; i++) {
            if (u >> i & 1) count++

            if (v >> i & 1) {
                if(count<0) ans = false
                count--
            }
        }
        console.log(ans?'YES':'NO')

    })
}

function checkString(a) {
    // console.log(a)
    var count = 0
    var res = true
    for (let i = 0; i < a.length; i++) {
        if (a[i] === '(') count++
        else {
            count--
            if (count < 0) res = false
        }
    }
    if (count !== 0) res = false

    return res

}


const init = () => {
  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();
  });

  global.readline = () => {
    return inputString[currentLine++];
  }
};

if (typeof readline === 'undefined') {
  init();
}

const print = (...args) => {
  console.log(...args);
};

const isBalanced = (s) => {
  let r_cnt = 0;
  let l_cnt = 0;
  for (let i = 0; i < s.length; i++) {
    if (s[i] === ')') r_cnt++;
    if (s[i] === '(') l_cnt++;
  }
  return r_cnt === l_cnt;
};

const main = () => {
  let n = parseInt(readline());
  let s = readline();
  if (!isBalanced(s)) return print(-1);

  let needs = false;
  let l_cnt = 0;
  let r_cnt = 0;
  let left = n;
  let cnt = 0;
  for (let i = 0; i < n; i++) {
    if (s[i] === ')') r_cnt++;
    if (s[i] === '(') l_cnt++;
    // print({ r_cnt, l_cnt, left, i, needs });
    if (r_cnt > l_cnt) {
      left = Math.min(left, i);
      needs = true;
    } else if (needs && r_cnt === l_cnt) {
      needs = false;
      cnt += i - left + 1;
      left = n;
    }
  }
  print(cnt)
};

function main(raw) {
    var lines = raw.trim().split("\n").map(function (l) { return l.trim(); });
    var l = parseInt(lines.shift(), 10);
    console.log(solve(l, lines.shift()));
}
function solve(l, s) {
    var cnt = 0;
    var cval = 0;
    var countingwrong = false;
    var failcnt = 0;
    for (var i = 0; i < l; i++) {
        if (s[i] === "(") {
            cval++;
        }
        else {
            cval--;
        }
        if (countingwrong) {
            if (cval === 0) {
                failcnt++;
                cnt += failcnt;
                failcnt = 0;
                countingwrong = false;
            }
            else {
                failcnt++;
            }
        }
        else if (cval < 0) {
            countingwrong = true;
            failcnt++;
        }
    }
    if (cval !== 0) {
        return -1;
    }
    return cnt;
}
(function () {
    var d = "";
    process.stdin.on("data", function (c) { return d += c; });
    process.stdin.on("end", function () { return main(d); });
})();

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var n = +readline();
  var str = readline();

  var bracketsSum = 0;
  var wrongBracketsSum = 0;
  for (var i = 0; i < str.length; i++) {
    if (str[i] === "(") {
      if (bracketsSum === -1) {
        wrongBracketsSum++;
      }
      bracketsSum++;
    }
    if (str[i] === ")") {
      bracketsSum--;
    }
    if (bracketsSum < 0) {
      wrongBracketsSum++;
    }
  }
  if (bracketsSum !== 0) {
    print(-1);
    return;
  }
  print(wrongBracketsSum);
}
main()

const processData = (lines) => {
  const s = lines[1].split('')

  let balance = 0

  // const prefix = []
  let acc = 0
  let neg = false
  let sum = 0
  let peak = 0
  for (let j =0; j<s.length; j++) {
    const ch = s[j]
    if (ch === '(') {
      acc++
      // prefix.push(acc)
      balance++
    } else {
      acc--
      // prefix.push(acc)
      balance--
    }
    if (!neg && acc < 0) {
      neg = true
      peak = j
    }
    if (acc === 0) {
      if (neg) {
        // console.log(j, peak)
        sum += (j - peak)+1
      }
      neg = false
    }
  }
  // console.log(prefix)
  if (balance !== 0) {
    console.log(-1)
  } else {
    console.log(sum)
  }
}

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*/
  processData(lines)
})

const processData = (lines) => {
  const s = lines[1].split('')

  let balance = 0

  const prefix = []
  let acc = 0
  let neg = false
  let sum = 0
  let peak = 0
  for (let j =0; j<s.length; j++) {
    const ch = s[j]
    if (ch === '(') {
      acc++
      prefix.push(acc)
      balance++
    } else {
      acc--
      prefix.push(acc)
      balance--
    }
    if (!neg && acc < 0) {
      neg = true
      peak = j
    }
    if (acc === 0) {
      if (neg) {
        sum += j - peak
      }
      neg = false
    }
  }
  if (balance !== 0) {
    console.log(-1)
  } else {
    console.log(sum)
  }
}

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*/
  processData(lines)
})

const processData = (lines) => {
  const s = lines[1].split('')

  let balance = 0

  // const prefix = []
  let acc = 0
  let neg = false
  let sum = 0
  let peak = 0
  for (let j =0; j<s.length; j++) {
    const ch = s[j]
    if (ch === '(') {
      acc++
      // prefix.push(acc)
      balance++
    } else {
      acc--
      // prefix.push(acc)
      balance--
    }
    if (!neg && acc < 0) {
      neg = true
      peak = j
    }
    if (acc === 0) {
      if (neg) {
        console.log(j, peak)
        sum += (j - peak)+1
      }
      neg = false
    }
  }
  // console.log(prefix)
  if (balance !== 0) {
    console.log(-1)
  } else {
    console.log(sum)
  }
}

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*/
  processData(lines)
})

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var n = +readline();
  var str = readline();

  var bracketsSum = 0;
  var wrongBracketsSum = 0;
  for (var i = 0; i < str.length; i++) {
    if (str[i] === "(") {
      if (bracketsSum === -1) {
        wrongBracketsSum++;
      }
      bracketsSum++;
    }
    if (str[i] === ")") {
      bracketsSum--;
    }
    if (bracketsSum < 0) {
      wrongBracketsSum++;
    }
  }
  if (bracketsSum !== 0) {
    print(-1);
  }
  print(wrongBracketsSum);
}
main()


'use strict';

function solve(n, m, a, b) {
  let t = a.reduce((a, b) => a ^ b, 0);
  if (t === 0) return 'YES';
  if (m < 3) return 'NO';
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        d = new Array(n).fill(0);
  let idx = 0;
  const add = (i, j) => {
    e[idx] = j, d[j]++, ne[idx] = h[i], h[i] = idx++;
  };
  for (let [u, v] of b) {
    add(u - 1, v - 1);
    add(v - 1, u - 1);
  }
  const vis = new Array(n);
  let res = 0;
  const dfs1 = RTI(i => {
    vis[i] = 1;
    const inside = () => {
      let params = [];
      for (let k = h[i]; k !== -1; k = ne[k]) {
        const j = e[k];
        if (vis[j]) continue;
        params.push([j]);
      }
      return params;
    };
    const after = (...result) => {
      let ans = result.reduce((a, b) => a ^ b, 0) ^ a[i];
      if (ans === t) {
        res++;
        ans = 0;
      }
      return ans;
    };
    return [inside, after];
  });
  dfs1(0);
  return res >= 2 ? 'YES' : 'NO';
}
function RTI(fn) {
  let res;
  const createNode = args => {
    return {
      args,
      result: [],
      curIndex: 0
    };
  };
  const dfs = (...args) => {
    const root = createNode([args]);
    root.cb = result => res = result;
    const callStack = [root];
    while (callStack.length) {
      let curCall = callStack[callStack.length - 1];
      while (curCall && curCall.args.length === curCall.curIndex) {
        var _curCall$cb, _curCall;
        const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, ...curCall.result);
        callStack.pop();
        curCall = callStack[callStack.length - 1];
        if (curCall) curCall.result[curCall.curIndex++] = res;
      }
      if (!curCall) break;
      const {
        args,
        curIndex
      } = curCall;
      {
        const res = fn(...args[curIndex]);
        const [inside, after] = res;
        let nextCall = inside();
        const node = createNode(nextCall);
        node.cb = after;
        callStack.push(node);
      }
    }
    return res;
  };
  return dfs;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = (await read()).split(' ').map(Number);
      const b = [];
      let tmp = n - 1;
      while (tmp--) {
        b.push((await read()).split(' ').map(Number));
      }
      res[i] = solve(n, m, a, b);
    }
    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);
});

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++]
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))
        l += n - 1
        console.log(solve(n, k, arr, edges))
    }
// })()
})

function solve(n, k, arr, edges) {
    const xor = arr.reduce((s, x) => s ^ x, 0)
    if (!xor) return 'YES'
    if (k - 1 < 2) return 'NO'
// console.log(xor)
    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })
    return dfs(adj, 1, {}, arr, xor) ? 'YES' : 'NO'
}
function dfs(adj, r, visited, arr, target) {
    const stack = [[r, 0, -1]]
    const xor = []
    let found = 0
    let cut = 0
    while (stack.length) {
        const [u, i, p] = stack[stack.length - 1]
        visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const v = nb[i]
            if (v !== p) {
                stack.push([v, 0, u])
            }
        } else {
            // last visited
            cut++
            xor[u] = arr[u - 1]
            nb.forEach(v => {
                if (v !== p) xor[u] ^= xor[v]
            })
            if (xor[u] === target) {
                found++
                // console.log('found', cut, arr.length)
                if (found === 2) return true
                xor[u] = 0
            }
            stack.pop()
        }
    }
    // console.log(xor)
    return false
}

'use strict';

function solve(n, m, a, b) {
  let t = a.reduce((a, b) => a ^ b, 0);
  if (t === 0) return 'YES';
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        d = new Array(n).fill(0);
  let idx = 0;
  const add = (i, j) => {
    e[idx] = j, d[j]++, ne[idx] = h[i], h[i] = idx++;
  };
  for (let [u, v] of b) {
    add(u - 1, v - 1);
    add(v - 1, u - 1);
  }
  const vis = new Array(n);
  let res = 0;
  const dfs1 = RTI(i => {
    vis[i] = 1;
    const inside = () => {
      let params = [];
      for (let k = h[i]; k !== -1; k = ne[k]) {
        const j = e[k];
        if (vis[j]) continue;
        params.push([j]);
      }
      return params;
    };
    const after = (...result) => {
      let ans = result.reduce((a, b) => a ^ b, 0) ^ a[i];
      if (ans === t) {
        res++;
        ans = 0;
      }
      return ans;
    };
    return [inside, after];
  });
  dfs1(0);
  return res >= 2 ? 'YES' : 'NO';
}
function RTI(fn) {
  let res;
  const createNode = args => {
    return {
      args,
      result: [],
      curIndex: 0
    };
  };
  const dfs = (...args) => {
    const root = createNode([args]);
    root.cb = result => res = result;
    const callStack = [root];
    while (callStack.length) {
      let curCall = callStack[callStack.length - 1];
      while (curCall && curCall.args.length === curCall.curIndex) {
        var _curCall$cb, _curCall;
        const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, ...curCall.result);
        callStack.pop();
        curCall = callStack[callStack.length - 1];
        if (curCall) curCall.result[curCall.curIndex++] = res;
      }
      if (!curCall) break;
      const {
        args,
        curIndex
      } = curCall;
      {
        const res = fn(...args[curIndex]);
        const [inside, after] = res;
        let nextCall = inside();
        const node = createNode(nextCall);
        node.cb = after;
        callStack.push(node);
      }
    }
    return res;
  };
  return dfs;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = (await read()).split(' ').map(Number);
      const b = [];
      let tmp = n - 1;
      while (tmp--) {
        b.push((await read()).split(' ').map(Number));
      }
      res[i] = solve(n, m, a, b);
    }
    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, m, a, b) {
  let t = a.reduce((a, b) => a ^ b, 0);
  if (t === 0) return 'YES';
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        d = new Array(n).fill(0);
  let idx = 0;
  const add = (i, j) => {
    e[idx] = j, d[j]++, ne[idx] = h[i], h[i] = idx++;
  };
  for (let [u, v] of b) {
    add(u - 1, v - 1);
    add(v - 1, u - 1);
  }
  const vis = new Array(n);
  let res = 0;
  const dfs = i => {
    vis[i] = 1;
    let ans = 0;
    for (let k = h[i]; k !== -1; k = ne[k]) {
      const j = e[k];
      if (vis[j]) continue;
      let sum = dfs(j);
      if (sum === t) {
        res++;
        sum = 0;
      }
      ans ^= sum;
      if (ans === t) {
        res++;
        ans = 0;
      }
    }
    return ans ^ a[i];
  };
  dfs(0);
  return res > 2 ? 'YES' : '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, m] = (await read()).split(' ').map(Number);
      const a = (await read()).split(' ').map(Number);
      const b = [];
      let tmp = n - 1;
      while (tmp--) {
        b.push((await read()).split(' ').map(Number));
      }
      res[i] = solve(n, m, a, b);
    }
    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);
});

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++]
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))
        l += n - 1
        console.log(solve(n, k, arr, edges))
    }
// })()
})

function solve(n, k, arr, edges) {
    const xor = arr.reduce((s, x) => s ^ x, 0)
    if (!xor) return 'YES'
// console.log(xor)
    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })
    return dfs(adj, 1, {}, arr, xor) ? 'YES' : 'NO'
}
function dfs(adj, r, visited, arr, target) {
    const stack = [[r, 0, -1]]
    const xor = []
    let found = 0
    while (stack.length) {
        const [u, i, p] = stack[stack.length - 1]
        visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const v = nb[i]
            if (v !== p) {
                stack.push([v, 0, u])
            }
        } else {
            // last visited
            xor[u] = arr[u - 1]
            nb.forEach(v => {
                if (v !== p) xor[u] ^= xor[v]
            })
            if (xor[u] === target) {
                found++
                if (found === 2 && u !== r) return true
                xor[u] = 0
            }
            stack.pop()
        }
    }
    // console.log(xor)
    return false
}

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++]
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))
        l += n - 1
        console.log(solve(n, k, arr, edges))
    }
// })()
})

function solve(n, k, arr, edges) {
    const xor = arr.reduce((s, x) => s ^ x, 0)
    if (!xor) return 'YES'
// console.log(xor)
    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })
    return dfs(adj, 1, {}, arr, xor) ? 'YES' : 'NO'
}
function dfs(adj, r, visited, arr, target) {
    const stack = [[r, 0, -1]]
    const xor = []
    let found = 0
    while (stack.length) {
        const [u, i, p] = stack[stack.length - 1]
        visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const v = nb[i]
            if (v !== p) {
                stack.push([v, 0, u])
            }
        } else {
            // last visited
            xor[u] = arr[u - 1]
            nb.forEach(v => {
                if (v !== p) xor[u] ^= xor[v]
            })
            if (xor[u] === target) {
                found++
                if (found === 2) return true
                xor[u] = 0
            }
            stack.pop()
        }
    }
    // console.log(xor)
    return false
}

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++]
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))
        l += n - 1
        console.log(solve(n, k, arr, edges))
    }
// })()
})

function solve(n, k, arr, edges) {
    const xor = arr.reduce((s, x) => s ^ x, 0)
    if (!xor) return 'YES'

    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })
    return dfs(adj, 1, {}, arr, xor) ? 'YES' : 'NO'
}
function dfs(adj, r, visited, arr, target) {
    const stack = [[r, 0, -1]]
    const xor = []
    let found = 0
    while (stack.length) {
        const [u, i, p] = stack[stack.length - 1]
        visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const v = nb[i]
            if (v !== p) {
                stack.push([v, 0, u])
            }
        } else {
            // last visited
            xor[u] = arr[u]
            nb.forEach(v => {
                if (v !== p) xor[u] ^= xor[v]
            })
            if (xor[u] === target) {
                found++
                if (found === 2) return true
                xor[u] = 0
            }
            stack.pop()
        }
    }
    return false
}