'use strict';

function solve(n, a) {
  const topo = () => {
    const g = Array.from({
      length: n
    }, () => []);
    const add = (i, j) => g[i].push(j);
    for (let [i, j] of a) {
      add(i - 1, j - 1);
      add(j - 1, i - 1);
    }
    const query = [0];
    const g1 = Array.from({
      length: n
    }, () => []),
          d = new Array(n).fill(0);
    const add1 = (i, j) => {
      g1[i].push(j);
      d[j]++;
    };
    const st = [];
    for (let u of query) {
      st[u] = 1;
      for (let v of g[u]) {
        if (st[v]) continue;
        add1(v, u);
        query.push(v);
      }
    }
    return [g1, d];
  };
  const [g, d] = topo();
  const dp = Array.from({
    length: n
  }, () => [0, 1]);
  const temp = Array.from({
    length: n
  }, () => []);
  const query = [];
  for (let [i, di] of d.entries()) if (di === 0) query.push(i);
  for (let u of query) {
    for (let v of g[u]) {
      d[v]--;
      dp[v][1] += dp[u][1];
      temp[v].push(u);
      if (d[v] === 0) {
        query.push(v);
        let s0 = temp[v].reduce((a, b) => a + dp[b][0], 0);
        let max = 0;
        for (let i of temp[v]) {
          max = Math.max(max, s0 - dp[i][0] + dp[i][1] - 1);
        }
        dp[v][0] = max;
      }
    }
  }
  return dp[0][0];
}

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

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

'use strict';

function solve(n, a) {
  const g = Array.from({
    length: n
  }, () => []);
  const add = (i, j) => {
    g[i].push(j);
  };
  for (let [i, j] of a) {
    add(i - 1, j - 1);
    add(j - 1, i - 1);
  }
  g[0].push(-1);
  const st = new Array(n).fill(0);
  const cache = Array.from({
    length: n
  }, () => [-1, -1]);
  const dfs1 = RTI((i, state) => {
    if (st[i] !== 0) return [() => [], () => 0];
    if (cache[i][state] !== -1) return [() => [], () => cache[i][state]];
    st[i] = 1;
    let res = 0;
    if (state === 1) {
      const inside = () => {
        let calls = [];
        for (let j of g[i]) {
          calls.push([j, 1]);
        }
        return calls;
      };
      const after = (...args) => {
        res = args.reduce((a, b) => a + b, 1);
        st[i] = 0;
        cache[i][state] = res;
        return res;
      };
      return [inside, after];
    } else {
      if (g[i].length === 2) {
        const inside = () => [[g[i].filter(j => !st[j])[0], 1]];
        const after = (...args) => {
          res = args[0] - 1;
          st[i] = 0;
          cache[i][state] = res;
          return res;
        };
        return [inside, after];
      } else if (g[i].length > 2) {
        const [a, b] = g[i].filter(j => !st[j]);
        const inside = () => {
          return [[a, 0], [b, 1], [a, 1], [b, 0]];
        };
        const after = (...args) => {
          const [a, b, c, d] = args;
          res = Math.max(a + b - 1, c - 1 + d);
          st[i] = 0;
          cache[i][state] = res;
          return res;
        };
        return [inside, after];
      } else {
        const inside = () => {
          return [];
        };
        const after = () => {
          st[i] = 0;
          cache[i][state] = res;
          return res;
        };
        return [inside, after];
      }
    }
  });
  let res = dfs1(0, 0);
  return res;
}
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 res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      const a = [];
      let tmp = n - 1;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res.push(solve(n, a));
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

async function solve(n, a) {
  const g = Array.from({
    length: n
  }, () => []);
  const add = (i, j) => {
    g[i].push(j);
  };
  for (let [i, j] of a) {
    add(i - 1, j - 1);
    add(j - 1, i - 1);
  }
  g[0].push(-1);
  const st = new Array(n).fill(0);
  const cache = Array.from({
    length: n
  }, () => [-1, -1]);
  const dfs1 = RTI((i, state) => {
    if (st[i] !== 0) return [() => [], () => 0];
    if (cache[i][state] !== -1) return [() => [], () => cache[i][state]];
    st[i] = 1;
    let res = 0;
    if (state === 1) {
      const inside = () => {
        let calls = [];
        for (let j of g[i]) {
          calls.push([j, 1]);
        }
        return calls;
      };
      const after = (...args) => {
        res = args.reduce((a, b) => a + b, 1);
        st[i] = 0;
        cache[i][state] = res;
        return res;
      };
      return [inside, after];
    } else {
      if (g[i].length === 2) {
        const inside = () => [[g[i].filter(j => !st[j])[0], 1]];
        const after = (...args) => {
          res = args[0] - 1;
          st[i] = 0;
          cache[i][state] = res;
          return res;
        };
        return [inside, after];
      } else if (g[i].length > 2) {
        const [a, b] = g[i].filter(j => !st[j]);
        const inside = () => {
          return [[a, 0], [b, 1], [a, 1], [b, 0]];
        };
        const after = (...args) => {
          const [a, b, c, d] = args;
          res = Math.max(a + b - 1, c - 1 + d);
          st[i] = 0;
          cache[i][state] = res;
          return res;
        };
        return [inside, after];
      } else {
        const inside = () => {
          return [];
        };
        const after = () => {
          st[i] = 0;
          cache[i][state] = res;
          return res;
        };
        return [inside, after];
      }
    }
  });
  let res = dfs1(0, 0);
  return res;
}
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 res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      const a = [];
      let tmp = n - 1;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res.push(await solve(n, a));
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var worker_threads = require('worker_threads');

async function solve(n, a) {
  const g = Array.from({
    length: n
  }, () => []);
  const add = (i, j) => {
    g[i].push(j);
  };
  for (let [i, j] of a) {
    add(i - 1, j - 1);
    add(j - 1, i - 1);
  }
  g[0].push(-1);
  const st = new Array(n).fill(0);
  const cache = Array.from({
    length: n
  }, () => [-1, -1]);
  const dfs = async (i, state) => {
    if (st[i] !== 0) return 0;
    if (cache[i][state] !== -1) return cache[i][state];
    st[i] = 1;
    let res = 0;
    if (state === 1) {
      res = 1;
      for (let j of g[i]) {
        res += await dfs(j, 1);
      }
    } else {
      if (g[i].length === 2) {
        res = (await dfs(g[i].filter(j => !st[j])[0], 1)) - 1;
      } else if (g[i].length > 2) {
        const [a, b] = g[i].filter(j => !st[j]);
        res = Math.max((await dfs(a, 0)) + (await dfs(b, 1)) - 1, (await dfs(a, 1)) - 1 + (await dfs(b, 0)));
      }
    }
    st[i] = 0;
    cache[i][state] = res;
    return res;
  };
  return dfs(0, 0);
}

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

let str = '';
function exec(script, data) {
  return new Promise((resolve, reject) => {
    const worker = new worker_threads.Worker(script, {
      workerData: data,
      eval: true
    });
    worker.on('message', resolve);
    worker.on('error', reject);
    worker.on('exit', code => {
      if (code !== 0) reject(new Error(`Worker stopped with exit code ${code}`));
    });
  });
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  str.split('\n').values();
  const script =
  `
const { workerData } = require('worker_threads')
const inputs = workerData.split('\\n').values()
function read() {
  return inputs.next().value.trim()
}
${solve.toString()}
${main.toString()}

void async function () {
  const output = await main(read)
  console.log(output)
}()
`;
  exec(script, str);
});

'use strict';

async function solve(n, a) {
  const g = Array.from({
    length: n
  }, () => []);
  const add = (i, j) => {
    g[i].push(j);
  };
  for (let [i, j] of a) {
    add(i - 1, j - 1);
    add(j - 1, i - 1);
  }
  g[0].push(-1);
  const st = new Array(n).fill(0);
  const cache = Array.from({
    length: n
  }, () => [-1, -1]);
  const dfs = async (i, state) => {
    if (st[i] !== 0) return 0;
    if (cache[i][state] !== -1) return cache[i][state];
    st[i] = 1;
    let res = 0;
    if (state === 1) {
      res = 1;
      for (let j of g[i]) {
        res += await dfs(j, 1);
      }
    } else {
      if (g[i].length === 2) {
        res = (await dfs(g[i].filter(j => !st[j])[0], 1)) - 1;
      } else if (g[i].length > 2) {
        const [a, b] = g[i].filter(j => !st[j]);
        res = Math.max((await dfs(a, 0)) + (await dfs(b, 1)) - 1, (await dfs(a, 1)) - 1 + (await dfs(b, 0)));
      }
    }
    st[i] = 0;
    cache[i][state] = res;
    return res;
  };
  return dfs(0, 0);
}

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

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

'use strict';

function solve(n, a) {
  const topo = () => {
    const g = Array.from({
      length: n
    }, () => []);
    const add = (i, j) => g[i].push(j);
    for (let [i, j] of a) {
      add(i - 1, j - 1);
      add(j - 1, i - 1);
    }
    const query = [0];
    const g1 = Array.from({
      length: n
    }, () => []),
          d = new Array(n).fill(0);
    const add1 = (i, j) => {
      g1[i].push(j);
      d[j]++;
    };
    const st = [];
    for (let u of query) {
      st[u] = 1;
      for (let v of g[u]) {
        if (st[v]) continue;
        add1(v, u);
        query.push(v);
      }
    }
    return [g1, d];
  };
  const [g, d] = topo();
  const dp = Array.from({
    length: n
  }, () => [0, 0, 1]);
  const temp = Array.from({
    length: n
  }, () => []);
  const query = [];
  for (let [i, di] of d.entries()) if (di === 0) query.push(i);
  for (let u of query) {
    for (let v of g[u]) {
      d[v]--;
      dp[v][2] += dp[u][2];
      dp[v][0] += dp[u][2];
      temp[v].push(u);
      if (d[v] === 0) {
        query.push(v);
        let s0 = temp[v].reduce((a, b) => a + dp[b][1], 0);
        let max = 0;
        for (let i of temp[v]) {
          max = Math.max(max, s0 - dp[i][1] + dp[i][0]);
        }
        dp[v][1] = max;
      }
    }
  }
  return dp[0][1];
}

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

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

'use strict';

var worker_threads = require('worker_threads');

function solve(n, a) {
  const g = Array.from({
    length: n
  }, () => []);
  const add = (i, j) => {
    g[i].push(j);
  };
  for (let [i, j] of a) {
    add(i - 1, j - 1);
    add(j - 1, i - 1);
  }
  g[0].push(-1);
  const st = new Array(n).fill(0);
  const cache = Array.from({
    length: n
  }, () => [-1, -1]);
  const dfs = (i, state) => {
    if (st[i] !== 0) return 0;
    if (cache[i][state] !== -1) return cache[i][state];
    st[i] = 1;
    let res = 0;
    if (state === 1) {
      res = 1;
      for (let j of g[i]) {
        res += dfs(j, 1);
      }
    } else {
      if (g[i].length === 2) {
        res = dfs(g[i].filter(j => !st[j])[0], 1) - 1;
      } else if (g[i].length > 2) {
        const [a, b] = g[i].filter(j => !st[j]);
        res = Math.max(dfs(a, 0) + dfs(b, 1) - 1, dfs(a, 1) - 1 + dfs(b, 0));
      }
    }
    st[i] = 0;
    cache[i][state] = res;
    return res;
  };
  return dfs(0, 0);
}

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

let str = '';
function exec(script, data) {
  return new Promise((resolve, reject) => {
    const worker = new worker_threads.Worker(script, {
      workerData: data,
      eval: true
    });
    worker.on('message', resolve);
    worker.on('error', reject);
    worker.on('exit', code => {
      if (code !== 0) reject(new Error(`Worker stopped with exit code ${code}`));
    });
  });
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  str.split('\n').values();
  const script =
  `
const { workerData } = require('worker_threads')
const inputs = workerData.split('\\n').values()
function read() {
  return inputs.next().value.trim()
}
${solve.toString()}
${main.toString()}

void async function () {
  const output = await main(read)
  console.log(output)
}()
`;
  exec(script, str);
});

'use strict';

var worker_threads = require('worker_threads');

async function solve(n, a) {
  const g = Array.from({
    length: n
  }, () => []);
  const add = (i, j) => {
    g[i].push(j);
  };
  for (let [i, j] of a) {
    add(i - 1, j - 1);
    add(j - 1, i - 1);
  }
  g[0].push(-1);
  const st = new Array(n).fill(0);
  const cache = Array.from({
    length: n
  }, () => [-1, -1]);
  const dfs = async (i, state) => {
    if (st[i] !== 0) return 0;
    if (cache[i][state] !== -1) return cache[i][state];
    st[i] = 1;
    let res = 0;
    if (state === 1) {
      res = 1;
      for (let j of g[i]) {
        res += await dfs(j, 1);
      }
    } else {
      if (g[i].length === 2) {
        res = (await dfs(g[i].filter(j => !st[j])[0], 1)) - 1;
      } else if (g[i].length > 2) {
        const [a, b] = g[i].filter(j => !st[j]);
        res = Math.max((await dfs(a, 0)) + (await dfs(b, 1)) - 1, (await dfs(a, 1)) - 1 + (await dfs(b, 0)));
      }
    }
    st[i] = 0;
    cache[i][state] = res;
    return res;
  };
  return dfs(0, 0);
}

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

let inputs,
    str = '';
function exec(script, data) {
  return new Promise((resolve, reject) => {
    const worker = new worker_threads.Worker(script, {
      workerData: data,
      eval: true
    });
    worker.on('message', resolve);
    worker.on('error', reject);
    worker.on('exit', code => {
      if (code !== 0) reject(new Error(`Worker stopped with exit code ${code}`));
    });
  });
}
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 script =
  `
const { workerData } = require('worker_threads')
let idx = 0
function read() {
  return workerData[idx++]
}
${main.toString()}

void async function () {
  const output = main(read)
  console.log(output)
}
`;
  exec(script, inputs);
});

'use strict';

const {
  Worker, isMainThread, parentPort, workerData
} = require('worker_threads');

function parseJSAsync(script, workerData) {
  return new Promise((resolve, reject) => {
    const worker = new Worker(script, { eval: true, workerData });
    worker.on('message', resolve);
    worker.on('error', reject);
    worker.on('exit', (code) => {
      if (code !== 0)
        reject(new Error(`Worker stopped with exit code ${code}`));
    });
  });
};

var readline = require('readline');

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

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

async function main(read) {
  let t = Number(await read());
  let res = [];
  while (t--) {
    const n = Number(await read());
    const a = (await read()).split(' ').map(Number);
    const b = (await read()).split(' ').map(Number);
    const d = (await read()).split(' ').map(Number);
    // res.push(await solve(n, a, b, d));
    const ans = await parseJSAsync(`
        const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
        parentPort.postMessage(solve(...workerData))
        function solve(n, a, b, d) {
          const MOD = BigInt(10 ** 9 + 7);
          const set = new Set();
          {
            const g = Array.from({
              length: n + 1
            }, () => [0, 0]);
            for (let i = 0; i < n; i++) {
              g[a[i]][0] = i;
              g[b[i]][1] = i;
            }
            for (let i = 0; i < n; i++) {
              if (d[i] !== 0) {
                const queue = [a[i], b[i]];
                for (let j of queue) {
                  set.add(j);
                  for (let k of [b[g[j][0]], a[g[j][1]]]) {
                    if (set.has(k)) continue;
                    queue.push(k);
                  }
                }
              } else if (a[i] === b[i]) {
                set.add(a[i]);
              }
            }
          }
          const g = Array.from({
            length: n + 1
          }, () => new Set());
          for (let i = 0; i < n; i++) {
            if (d[i] === 0) {
              const u = a[i],
                v = b[i];
              if (set.has(u) || set.has(v)) continue;
              g[u].add(v);
              g[v].add(u);
            }
          }
          const tarjan = () => {
            const dfn = [],
              low = [],
              stack = [],
              set = new Set(),
              map = new Map();
            let time = 1,
              idx = 0;
            const dfs = u => {
              dfn[u] = low[u] = time++;
              stack.push(u);
              set.add(u);
              for (let v of g[u]) {
                if (!dfn[v]) {
                  dfs(v);
                  low[u] = Math.min(low[u], low[v]);
                } else if (set.has(v)) {
                  low[u] = Math.min(low[u], dfn[v]);
                }
              }
              if (dfn[u] === low[u]) {
                while (true) {
                  const j = stack.pop();
                  set.delete(j);
                  map.set(j, idx);
                  if (j === u) break;
                }
                idx++;
              }
            };
            for (let i = 1; i <= n; i++) {
              if (!dfn[i] && g[i].size) dfs(i);
            }
            return BigInt(2) ** BigInt(idx) % MOD;
          };
          return tarjan();
        }
    `, [n, a, b, d])
    res.push(ans)
  }
  console.log(res.map(num => num.toString()).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';

var readline = require('readline');

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

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

async function solve(n, a, b, d) {
  const MOD = BigInt(10 ** 9 + 7);
  const set = new Set();
  {
    const g = Array.from({
      length: n + 1
    }, () => [0, 0]);
    for (let i = 0; i < n; i++) {
      g[a[i]][0] = i;
      g[b[i]][1] = i;
    }
    for (let i = 0; i < n; i++) {
      if (d[i] !== 0) {
        const queue = [a[i], b[i]];
        for (let j of queue) {
          set.add(j);
          for (let k of [b[g[j][0]], a[g[j][1]]]) {
            if (set.has(k)) continue;
            queue.push(k);
          }
        }
      } else if (a[i] === b[i]) {
        set.add(a[i]);
      }
    }
  }
  const g = Array.from({
    length: n + 1
  }, () => new Set());
  for (let i = 0; i < n; i++) {
    if (d[i] === 0) {
      const u = a[i],
            v = b[i];
      if (set.has(u) || set.has(v)) continue;
      g[u].add(v);
      g[v].add(u);
    }
  }
  const tarjan = async () => {
    const dfn = [],
          low = [],
          stack = [],
          set = new Set(),
          map = new Map();
    let time = 1,
        idx = 0;
    const dfs = RTI((u, p) => {
      const before = () => {
        dfn[u] = low[u] = time++;
        stack.push(u);
        set.add(u);
      };
      const inside = () => {
        let res = [];
        for (let v of g[u]) {
          if (!dfn[v]) {
            res.push([v, u]);
          } else if (set.has(v)) {
            low[u] = Math.min(low[u], dfn[v]);
          }
        }
        return res;
      };
      const after = () => {
        if (dfn[u] === low[u]) {
          while (true) {
            const j = stack.pop();
            set.delete(j);
            map.set(j, idx);
            if (j === u) break;
          }
          idx++;
        }
        if (p !== -1) low[p] = Math.min(low[p], low[u]);
      };
      return [before, inside, after];
    });
    for (let i = 1; i <= n; i++) {
      if (!dfn[i] && g[i].size) dfs(i, -1);
    }
    return BigInt(2) ** BigInt(idx) % MOD;
  };
  return tarjan();
}
function RTI(fn) {
  const done = () => {};
  const dfs = (...args) => {
    const callStack = [[done, args]];
    while (callStack.length) {
      let curCall = callStack[callStack.length - 1];
      while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 1) {
        var _curCall;
        const after = curCall.pop();
        after();
        callStack.pop();
        curCall = callStack[callStack.length - 1];
        if (curCall && curCall.length > 1) curCall.pop();
      }
      if (!curCall) break;
      const args = curCall[curCall.length - 1];
      const [before, inside, after] = fn(...args);
      before();
      let nextCall = inside();
      callStack.push([after, ...nextCall]);
    }
  };
  return dfs;
}

async function main(read) {
  let t = Number(await read());
  let res = [];
  while (t--) {
    const n = Number(await read());
    const a = (await read()).split(' ').map(Number);
    const b = (await read()).split(' ').map(Number);
    const d = (await read()).split(' ').map(Number);
    res.push(await solve(n, a, b, d));
  }
  console.log(res.map(num => num.toString()).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';

function solve(n, a) {
  const g = Array.from({
    length: n
  }, () => []);
  const add = (i, j) => {
    g[i].push(j);
  };
  for (let [i, j] of a) {
    add(i - 1, j - 1);
    add(j - 1, i - 1);
  }
  g[0].push(-1);
  const st = new Array(n).fill(0);
  const cache = Array.from({
    length: n
  }, () => [-1, -1]);
  const dfs = (i, state) => {
    if (st[i] !== 0) return 0;
    if (cache[i][state] !== -1) return cache[i][state];
    st[i] = 1;
    let res = 0;
    if (state === 1) {
      res = 1;
      for (let j of g[i]) {
        res += dfs(j, 1);
      }
    } else {
      if (g[i].length === 2) {
        res = dfs(g[i].filter(j => !st[j])[0], 1) - 1;
      } else if (g[i].length > 2) {
        const [a, b] = g[i].filter(j => !st[j]);
        res = Math.max(dfs(a, 0) + dfs(b, 1) - 1, dfs(a, 1) - 1 + dfs(b, 0));
      }
    }
    st[i] = 0;
    cache[i][state] = res;
    return res;
  };
  return dfs(0, 0);
}

async function main(read) {

    let res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      const a = [];
      let tmp = n - 1;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res.push(solve(n, a));
    }
    return res.join('\n');
}

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);
  console.log(output);
});

'use strict';

function solve(n, a) {
  const g = Array.from({
    length: n
  }, () => []);
  const add = (i, j) => {
    g[i].push(j);
  };
  for (let [i, j] of a) {
    add(i - 1, j - 1);
    add(j - 1, i - 1);
  }
  g[0].push(-1);
  const st = new Array(n).fill(0);
  const cache = Array.from({
    length: n
  }, () => [-1, -1]);
  const dfs = (i, state) => {
    if (st[i] !== 0) return 0;
    if (cache[i][state] !== -1) return cache[i][state];
    st[i] = 1;
    let res = 0;
    if (state === 1) {
      res = 1;
      for (let j of g[i]) {
        res += dfs(j, 1);
      }
    } else {
      if (g[i].length === 2) {
        res = dfs(g[i].filter(j => !st[j])[0], 1) - 1;
      } else if (g[i].length > 2) {
        const [a, b] = g[i].filter(j => !st[j]);
        res = Math.max(dfs(a, 0) + dfs(b, 1) - 1, dfs(a, 1) - 1 + dfs(b, 0));
      }
    }
    st[i] = 0;
    cache[i][state] = res;
    return res;
  };
  return dfs(0, 0);
}

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

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

'use strict';

function solve(n, a) {
  const g = Array.from({
    length: n
  }, () => []);
  const add = (i, j) => {
    g[i].push(j);
  };
  for (let [i, j] of a) {
    add(i - 1, j - 1);
    add(j - 1, i - 1);
  }
  g[0].push(-1);
  const st = new Array(n).fill(0);
  const dfs = (i, state) => {
    if (st[i] !== 0) return 0;
    st[i] = 1;
    let res = 0;
    if (state === 1) {
      res = 1;
      for (let j of g[i]) {
        res += dfs(j, 1);
      }
    } else {
      if (g[i].length === 2) {
        res = dfs(g[i].filter(j => !st[j])[0], 1) - 1;
      } else if (g[i].length > 2) {
        const [a, b] = g[i].filter(j => !st[j]);
        res = Math.max(dfs(a, 0) + dfs(b, 1) - 1, dfs(a, 1) - 1 + dfs(b, 0));
      }
    }
    st[i] = 0;
    return res;
  };
  return dfs(0, 0);
}

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

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


var n = parseInt(readline());
var is_possible = false;
var seat_config = [];

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

    var tokens = readline().split("|");
    for(var j = 0; j <= 1; j++) {

        if(tokens[j] == "OO") {

            if(!is_possible) {
                is_possible = true;
                tokens[j] = "++";
            }
        }
    }

    seat_config[i] = tokens[0] + "|" + tokens[1];
}

print(is_possible ? 'YES' : 'NO');
if(is_possible)
    print(seat_config.join("\n"));

var rowNum = readline(),
    rows = [],
    hasSeat = false;

for (var i = 0; i < rowNum; i++) {
    rows[i] = readline().split('');
    if (rows[i][0] === rows[i][1] && rows[i][0] === 'O' && !hasSeat) {
        hasSeat = true;
        rows[i][0] = '+';
        rows[i][1] = '+';
    }
    if (rows[i][3] === rows[i][4] && rows[i][3] === 'O' && !hasSeat) {
        hasSeat = true;
        rows[i][3] = '+';
        rows[i][4] = '+';
    }
}

if (hasSeat === false) {
    print('NO');
} else {
    print('YES');
    for (var i = 0; i < rowNum; i++) {
        print(rows[i].join(''));
    }
}

var n = +readline();
var obj = {}, str, b = false, res = "";

for(var i = 0; i < n; i++) {
    str = readline();
    if (!b) {
        str = str.replace("OO", "++");
        if ( str.indexOf("++") != -1 )
            b = true;
    }
    res += str + '\n';
}

if (b) {
    print("YES");
    print(res);
} else
    print("NO");
//print(res);

var n;
var arr=[];

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

var flag=false;
for(i=0;i<n;i++){
    var pos = arr[i].indexOf('OO');
    if(pos!=-1){
        flag=true;
        if(pos==0){
            arr[i]='++'+arr[i].slice(2);
        }else{
            arr[i]=arr[i].slice(0,3)+'++';
        }
        break;
    }
}

if(flag){
    print('YES');
    arr.forEach(function(item){
        print(item);
    });
}else{
    print('NO');
}

var n = readline();
var reg = /OO/
var str = "";

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

if (reg.test(str))
{
 print("YES")
 print(str.replace(reg, "++"));
}
else print("NO");

var n =  Number(readline());
var bus = [];
var checkPlace = false;

for (var i=0; i<n; i++) {
    var s = readline();
    if (!checkPlace && s.match(/OO/)) {
        s = s.replace(/OO/, '++');
        checkPlace = true;
    }
    bus.push(s);
}

if (checkPlace) {
    print( "YES" );
    print( bus.join( "\n" ) );
} else {
    print( "NO" );
}

var n = readline();
var totInput = "";
for (var i = 0 ; i < n ; i ++)
{
    totInput += '\n' + readline();
}
var ans = totInput.replace('OO','++')
write(ans !== totInput ? ("YES" + ans) : "NO")

"use strict";

var n = +readline();

var input = ''
for (var i = 0; i < n; ++i) {
   input += '\n' + readline();
}

var result = input.replace('OO', '++');

write(result !== input ? ('YES' + result) : 'NO');

if (!readline) {
    var _i = 0;
    var readline = function() {
        _i ++;

        switch (_i) {
            case 1: return '6';
            case 2: return 'OO|OX';
            case 3: return 'XO|XX';
            case 4: return 'OX|OO';
            case 5: return 'XX|OX';
            case 6: return 'OO|OO';
            case 7: return 'OO|XX';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = [];
var yes = false;

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

    if (!yes) {
        if (s[0] == 'O' && s[1] == 'O') {
            yes = true;
            s = '++' + s.substr(2, 3);
        } else if (s[3] == 'O' && s[4] == 'O') {
            yes = true;
            s = s.substr(0, 3) + '++';
        }
    }

    a.push(s);
}

if (yes) {
    write('YES\n');
    write(a.join('\n'));
} else {
    write('NO');
}

var n = parseInt(readline());
var pattern = /OO/;
var rows = [];
var found = false;
for ( var i = 0; i < n; ++i ) {
    var row = readline();
    if ( !found && row.match( pattern ) ) {
        row = row.replace( pattern, "++" );
        found = true;

    }
    rows.push( row );
}

if (found) {
    print( "YES" );
    print( rows.join( "\n" ) );
} else {
    print( "NO" );
}

var n = parseInt(readline());

var bus = [];
var seatAvailable = false;

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

    var seats = readline().split("|");

    if (!seatAvailable && seats.includes('OO')) {

        var index = seats.indexOf('OO');

        seats[index] = '++';

        seatAvailable = true;
    }

    bus.push(seats.join('|'));
}

if (seatAvailable) {
    print('YES');

    for (var j = 0; j < n; j++) {
        print(bus[j]);
    }

} else {
    print('NO');
}

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

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

    console.log(main());
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

const main = () => {
  const inputs = [];
  let isFound = false;
  let result = "";
  const inputCount = readline();

  for (let i = 0; i < inputCount; i+= 1) {
    let input = readline();

    if (!isFound && input.indexOf("OO") >= 0) {
      isFound = true

      input = input.replace("OO", "++")
    }

    if (i + 1 === inputCount) {
      result += input
    } else {
      result += input + '\n'
    }
  }

  if (!isFound) {
    return "NO";
  }

  return "YES\n" + result;
}

function main() {
    // write code here:
    const n = Number(stdin[0]);
    var say;
    var reg = /OO/;
    for (let i = 1; i <= n; i++) {
        if (reg.test(stdin[i])) {
            stdin[0] = 'YES';
            stdin[i] = stdin[i].replace(reg, '++');
            break;
        } else {
            stdin[0] = 'NO';
        }
    }
    if (stdin[0] === 'YES') {
        for (let j = 0; j <= n; j++) {
            console.log(stdin[j]);
        }
    } else {
        console.log(stdin[0]);
    }
}

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

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

let input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let _res = 'NO'
  let finish = false
  let count = 0
  let places = [...input.slice(1)]
  while (!finish) {
    if (count < places.length) {
      const el = places[count]
      if (el.match(/(OO)/g)) {
        places[count] = places[count].replace('OO', '++')
        _res = 'YES'
        finish = true
      }
    } else {
      finish = true
    }
    count++
  }
  if (_res === 'YES')
    console.log(_res + '\n' + places.join('\n'))
  else
    console.log(_res)
})

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = new Array(N);
  var isOK = false;
  for(var i = 0; i < N; i++){
    var tmp = next();
    if(!isOK && tmp.indexOf("OO") != -1){
      isOK = true;
      tmp = tmp.replace("OO", "++");
    }
    list[i] = tmp;
  }
  if(isOK){
    myout("YES");
    myout(myconv(list, 9));
  }else{
    myout("No");
  }
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
let ans = 'NO';
const arr = [];

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  if (d.includes('OO') && ans === 'NO') {
    ans = 'YES';
    arr.push(d.replace('OO', '++'));
  }
  else {
    arr.push(d);
  }

  c++;
});

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

  if (ans === 'YES') {
    for (let i = 0; i < arr.length; i++) {
      console.log(arr[i]);
    }
  }
});

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const [n] = input[0].split(' ').map(x => parseInt(x));

  const answer = []; let find = false;
  input.forEach((x, i) => {
    if (i === 0) return;

    let line = x.split('|');

    if (line[0][0] === 'O' && line[0][1] === 'O' && !find) {
      answer.push(`++|${line[1]}`); find = true;
    } else  if (line[1][0] === 'O' && line[1][1] === 'O' && !find) {
      answer.push(`${line[0]}|++`); find = true;
    } else {
      answer.push(`${line[0]}|${line[1]}`);
    }
  });

  if (!find) {
    console.log('NO');
  } else {
    console.log('YES');
    answer.forEach(x => console.log(x));
  }
});

function findAndCaptureSeats(config) {
    let regex = new RegExp('OO');
    let spaced = config.join(' ');
    if (regex.test(spaced)) {
        let seated = spaced.replace(regex, '++');
        seated = 'YES ' + seated;
        return seated.split(' ');
    }
    return ['NO'];
}

function processData(input) {
    let arr = input.split('\n');
    arr = arr.slice(1, arr.length);
    let config = findAndCaptureSeats(arr);
    for (let index = 0; index < config.length; index++) {
        console.log(config[index]);
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

var res = sol(readline());
print(res);

function sol(line1) {
    var input1 = line1.split(" ").map((x) => Number(x));

    var n = input1[0];

    var result = "NO";
    var seat = [];
    var isSeated = false;

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

        if (!isSeated && row.toString().indexOf("OO") > -1) {
            result = "YES";
            row = row.toString().replace("OO", "++", 1);
            seat.push(row);
            isSeated = true;
        }else{
            seat.push(row);
        }
    }

    if(result == "YES") {
        return result + "\n" + seat.join("\n");
    }else{
        return result;
    }
}

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

    console.log(main());
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

const main = () => {
  const inputs = [];
  let isFound = false;
  let result = "";
  const inputCount = readline();

  for (let i = 0; i < inputCount; i+= 1) {
    let input = readline();

    if (!isFound && input.indexOf("OO") >= 0) {
      isFound = true

      input = input.replace("OO", "++")
    }

    if (i + 1 === inputCount) { // To remove last new line
      result += input
    }

    result += input + '\n'
  }

  if (!isFound) {
    return "NO\n" + result;
  }

  return "YES\n" + result;
}

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

    console.log(main());
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const inputs = [];
  let isFound = false;
  let result = "";
  const inputCount = readline();

  for (let i = 0; i < inputCount; i+= 1) {
    let input = readline();

    if (!isFound && input.indexOf("OO") >= 0) {
      isFound = true

      input = input.replace("OO", "++")
    }

    result += input + '\n'
  }

  if (!isFound) {
    return "NO\n" + result;
  }

  return "YES\n" + result;
}

function main() {
    // write code here:
    const n = Number(stdin[0]);
    var say;
    var reg = /OO/g;
    for (let i = 1; i <= n; i++) {
        if (reg.test(stdin[i])) {
            stdin[0] = 'YES';
            stdin[i] = stdin[i].replace(reg, '++');
            break;
        } else {
            stdin[0] = 'NO';
        }
    }
    for(let j=0;j<=n;j++){
        console.log(stdin[j]);
    }
}

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() {
    // write code here:
    const n = Number(stdin[0]);
    var say;
    var reg = /OO/g;
    for (let i = 1; i <= n; i++) {
        if (reg.test(stdin[i])) {
            stdin[0] = 'YES';
            stdin[i] = stdin[i].replace(reg, '++');
            break;
        } else {
            stdin[0] = 'NO';
        }
    }
    if (stdin[0] === 'YES') {
        for (let j = 0; j <= n; j++) {
            console.log(stdin[j]);
        }
    } else {
        console.log(stdin[0]);
    }
}

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

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

let input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let _res = 'NO'
  let finish = false
  let count = 0
  let places = [...input.slice(1)]
  while (!finish) {
    if (count < places.length) {
      const el = places[count]
      if (el.match(/(OO)/g)) {
        places[count] = places[count].replace(/(OO)/g, '++')
        _res = 'YES'
        finish = true
      }
    } else {
      finish = true
    }
    count++
  }
  if (_res === 'YES')
    console.log(_res + '\n' + places.join('\n'))
  else
    console.log(_res)
})

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

let input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let _res = 'NO'
  let finish = false
  let count = 0
  let places = [...input.slice(1)]
  while (!finish) {
    if (count < places.length) {
      const el = places[count]
      if (el.match(/(OO)/g)) {
        places[count] = places[count].replace(/(OO)/g, '++')
        _res = 'YES'
        finish = true
      }
    } else {
      finish = true
    }
    count++
  }
  console.log(_res + '\n' + places.join('\n'))
})

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
let ans = 'NO';
const arr = [];

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  if (d.includes('OO') && ans === 'NO') {
    ans = 'YES';
    arr.push(d.replace('OO', '++'));
  }
  else {
    arr.push(d);
  }

  c++;
});

rl.on('close', () => {
  console.log(ans);
  for (let i = 0; i < arr.length; i++) {
    console.log(arr[i]);
  }
});

function findAndCaptureSeats(config) {
    console.log(config);
    let regex = new RegExp('OO');
    let spaced = config.join(' ');
    let seated = spaced.replace(regex, '++');
    return seated.split(' ');
}

function processData(input) {
    let arr = input.split('\n');
    arr = arr.slice(1, arr.length);
    let config = findAndCaptureSeats(arr);
    for (let index = 0; index < config.length; index++) {
        console.log(config[index]);
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

function findAndCaptureSeats(config) {
    console.log(config);
    let regex = new RegExp('OO');
    let spaced = config.join(' ');
    if (regex.test(spaced)) {
        let seated = spaced.replace(regex, '++');
        seated = 'YES ' + seated;
        return seated.split(' ');
    }
    return ['NO'];
}

function processData(input) {
    let arr = input.split('\n');
    arr = arr.slice(1, arr.length);
    let config = findAndCaptureSeats(arr);
    for (let index = 0; index < config.length; index++) {
        console.log(config[index]);
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

var res = sol(readline());
print(res);

function sol(line1) {
    var input1 = line1.split(" ").map((x) => Number(x));

    var n = input1[0];

    var result = "NO";
    var seat = [];
    var isSeated = false;

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

        if (!isSeated && row.toString().indexOf("OO") > -1) {
            result = "YES";
            row = row.toString().replace("OO", "++", 1);
            seat.push(row);
            isSeated = true;
        }else{
            seat.push(row);
        }
    }

    return result + "\n" + seat.join("\n");
}

var rowNum = readline(),
    rows = [],
    hasSeat = false;

for (var i = 0; i < rowNum; i++) {
    rows[i] = readline().split('');
    if (hasSeat) continue;
    hasSeat = true;
    if (rows[i][0] === rows[i][1] && rows[i][0] === 'O') {
        rows[i][0] = '+';
        rows[i][1] = '+';
    }

    if (rows[i][3] === rows[i][4] && rows[i][3] === 'O') {
        rows[i][3] = '+';
        rows[i][4] = '+';
    }
}

if (hasSeat === false) {
    print('NO');
} else {
    print('YES');
    for (var i = 0; i < rowNum; i++) {
        print(rows[i].join(''));
    }
}

var rowNum = readline(),
    rows = [],
    hasSeat = false;

for (var i = 0; i < rowNum; i++) {
    rows[i] = readline().split('');
    if (hasSeat) continue;
    hasSeat = true;
    if (rows[i][0] === rows[i][1] && rows[i][0] === 'O') {
        rows[i][0] = '+';
        rows[i][1] = '+';
    }

    if (rows[i][3] === rows[i][4] && rows[i][0] === 'O') {
        rows[i][3] = '+';
        rows[i][4] = '+';
    }
}

if (hasSeat === false) {
    print('NO');
} else {
    print('YES');
    for (var i = 0; i < rowNum; i++) {
        print(rows[i].join(''));
    }
}

var rowNum = readline(),
    rows = [],
    hasSeat = false;

for (var i = 0; i < rowNum; i++) {
    rows[i] = readline().split('');
    if (hasSeat) continue;
    if (rows[i][0] === rows[i][1] && rows[i][0] === 'O') {
        hasSeat = true;
        rows[i][0] = '+';
        rows[i][1] = '+';
    }

    if (rows[i][3] === rows[i][4] && rows[i][0] === 'O') {
        hasSeat = true;
        rows[i][3] = '+';
        rows[i][4] = '+';
    }
}

if (hasSeat === false) {
    print('NO');
} else {
    print('YES');
    for (var i = 0; i < rowNum; i++) {
        print(rows[i].join(''));
    }
}

var rowNum = readline(),
    rows = [],
    hasSeat = false;

for (var i = 0; i < rowNum; i++) {
    rows[i] = readline().split('');
    if (hasSeat) continue;
    if (rows[i][0] === rows[i][1] && rows[i][0] === 'O') {
        hasSeat = true;
        rows[i][0] = '+';
        rows[i][1] = '+';
    }

    if (rows[i][3] === rows[i][4] && rows[i][3] === 'O') {
        hasSeat = true;
        rows[i][3] = '+';
        rows[i][4] = '+';
    }
}

if (hasSeat === false) {
    print('NO');
} else {
    print('YES');
    for (var i = 0; i < rowNum; i++) {
        print(rows[i].join(''));
    }
}

var n = parseInt(readline());
var is_possible = false;
var seat_config = [];

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

    var tokens = readline().split("|");
    for(var j = 0; j <= 1; j++) {

        if(tokens[j] == "OO") {

            if(!is_possible) {
                is_possible = true;
                tokens[j] = "++";
            }
        }
    }

    seat_config[i] = tokens[0] + "|" + tokens[1];
}

print(is_possible ? 'YES' : 'NO');
print(seat_config.join("\n"));

var n = readline();
var reg = /OO/
var str = "";

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

if (reg.test(str))
{
 print("YES")
 print(str.replace(reg, "++"));
}
else print("NO");

n=Number(readline())
ss=new Array(n)
yes=false
for (i=0;i<n;++i){
    s=readline().split('|')
    if (!yes && (s[0]=='OO' || s[1]=='OO')) {
        yes = true
        s[0] = s[0].replace('OO', '++')
        s[1] = s[1].replace('OO', '++')
    }

    ss.push(s.join('|'))
}

if (yes) {
    print('YES')
    ss.forEach(s => print(s))
} else
    print('NO')

if (!readline) {
    var _i = 0;
    var readline = function() {
        _i ++;

        switch (_i) {
            case 1: return '6';
            case 2: return 'OO|OX';
            case 3: return 'XO|XX';
            case 4: return 'OX|OO';
            case 5: return 'XX|OX';
            case 6: return 'OO|OO';
            case 7: return 'OO|XX';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = [];
var yes = false;

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

    if (!yes) {
        if (s[0] == 'O' && s[1] == 'O') {
            yes = true;
            s = '++' + s.substr(2, 3);
        } else if (s[3] == 'O' && s[4] == 'O') {
            yes = true;
            s = s.substr(0, 3) + '++';
        }
    }

    a.push(s);
}

if (yes) {
    write('YES');
    write(a.join('\n'));
} else {
    write('NO');
}


'use-strict'

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

let data = '';
let currentLine = 0;

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

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

        let testCases = parseInt(readLine());
        while(testCases--)
        {
            let [n, k] = get_ints();
            let a = [];
            let b = new Array(n);
            let flag = true;
            if(n/k <= 2)
            {
                print(-1);
                continue;
            }
            for(let i = 1 ; i <= n; i++)
            {
                a.push(i);
            }
            for(let i = 0 ; i < n; i++)
            {
                b[i] = a.shift();
                if(k !== 0 )
                {
                    i++;
                  b[i] = a.pop();
                  k--;
                }
            }
            if(flag) print(b.join(' '));
        }

});

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

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

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

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------

function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var K = nextInt();
		if(K * 2 + 1 > N){
			myout(-1);
			continue;
		}
		var output = new Array(N);
		for(var j = 0; j < K; j++){
			output[j * 2 + 1] = N - j;
		}
		var now = 1;
		for(var j = 0; j < N; j++){
			if(output[j] == null){
				output[j] = now;
				now++;
			}
		}
		myout(myconv(output, 8));
	}
}

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve([n, k]) {
    let arr = [...Array(n).keys()].map(i => i + 1)
    if (k + 1 > Math.floor((n + 1) / 2) || n < 3 && k > 0) {
        console.log('-1')
        return
    }
    if (k === 0) {
        console.log(arr.join(' '))
        return
    }
    let arr2 = [], flag = false
    arr2.push(1)
    for (let i = 2; i <= n; ++i) {
        if (k > 0 && i % 2 === 0) {
            arr2.push(i + 1)
            k--
        } else {
            if (k > 0) arr2.push(i - 1)
            else {
                if (flag) arr2.push(i)
                else {
                    arr2.push(i - 1)
                    flag = true
                }
            }
        }
    }
    console.log(arr2.join(' '))
}

function main() {
    for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])
}

'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 = 21
var mod = 1000000007

// 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, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })

    if( n % 2===1 && k> Math.floor(n/2)) return console.log(-1)
    if( n % 2===0 && k>= Math.floor(n/2)) return console.log(-1)

    var ans = new Array(n)
    for (let j = 0; j < n; j++) {
      if(j % 2 ===1 && k >0){
        ans[j] = j+1
        ans[j+1] = j
        j++
        k--
        continue
      }
      ans[j] = j
    }

    console.log(ans.map(x=>x+1).join(' '))

  })
}

const t = readline();

for (var i = 0; i < parseInt(t); i++) {
  var input = readline().split(' ').map(d => parseInt(d));
  var n = input[0];
  var k = input[1];
  if (k >= parseInt((n + 1) / 2))
    print(-1);
  else {
    var a = [];
    var j = 1;
    var p = 0;
    var pk = 0;
    while (p < (n % 2? n - 1: n)) {
      a.push(j);
      p++;
      if (pk < k) {
        a.push(n - j + 1);
        p++;
        pk++;
      }
      j++;
    }
    if (n % 2)
      a.push(j);
    a.forEach((num) => write(num + ' '));
    write('\n');
  }
}

'use-strict'

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

let data = '';
let currentLine = 0;

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

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

        let testCases = parseInt(readLine());
        while(testCases--)
        {
            let [n, k] = get_ints();
            let a = [];
            let b = new Array(n);
            let flag = true;
            if(n/k <= 2)
            {
                print(-1);
                continue;
            }
            for(let i = 1 ; i <= n; i++)
            {
                a.push(i);
            }
            for(let i = 0 ; i < n; i++)
            {
                if(k !== 0 )
                {
                    if(isNaN(a[i+2])){
                        b[i] = a[i+1];
                        b[i+1] = a[i];
                        k--;
                        break;
                    }
                    b[i] = a[i];
                    b[i + 1] = a[i+2];
                    b[i + 2] = a[i+1];
                    i+=2;
                    k--;
                }
                else
                {
                    b[i] = a[i];
                }
            }
            if(flag && k === 0) print(b.join(' '))
            else print(-1)
        }

});

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

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

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

const t = readline();

for (var i = 0; i < parseInt(t); i++) {
  var input = readline().split(' ').map(d => parseInt(d));
  var n = input[0];
  var k = input[1];
  if (k >= parseInt((n + 1) / 2))
    print(-1);
  else {
    var a = [];
    var j = 1;
    var kp = 0;
    while (j <= parseInt(n / 2)) {
      a.push(j);
      if (kp < k) {
        a.push(n - j + 1);
        kp++;
        j++;
      } else {
        a.push(j + 1);
        j += 2;
      }
    }
    if (n % 2)
      a.push(j);
    a.forEach((num) => write(num + ' '));
    write('\n');
  }
}

const t = readline();

for (var i = 0; i < parseInt(t); i++) {
  var input = readline().split(' ').map(d => parseInt(d));
  var n = input[0];
  var k = input[1];
  if (k >= parseInt((n + 1) / 2))
    print(-1);
  else {
    var a = [];
    var j = 1;
    while (j <= parseInt(n / 2)) {
      a.push(j);
      a.push(n - j + 1);
      j++;
    }
    if (n % 2)
      a.push(j);
    a.forEach((num) => write(num + ' '));
    print('\n');
  }
}

const t = readline();

for (var i = 0; i < parseInt(t); i++) {
  var input = readline().split(' ').map(d => parseInt(d));
  var n = input[0];
  var k = input[1];
  if (k >= parseInt((n + 1) / 2))
    write(-1);
  else {
    var a = [];
    var j = 1;
    while (j <= parseInt(n / 2)) {
      a.push(j);
      a.push(n - j + 1);
      j++;
    }
    if (n % 2)
      a.push(j);
    a.forEach((num) => write(num + ' '));
  }
}

const t = readline();

for (var i = 0; i < t; i++) {
  const input = readline().split(' ').map(d => parseInt(d));
  const n = input[0];
  const k = input[1];
  if (k >= parseInt((n + 1) / 2))
    write(-1);
  else {
    var a = [];
    var j = 1;
    while (j <= parseInt(n / 2)) {
      a.push(j);
      a.push(n - j + 1);
      j++;
    }
    if (n % 2)
      a.push(j);
    a.forEach((num) => write(num + ' '));
  }
}

//const t = readline().split(' ').map((d) => parseInt(d));
const t = readline();

for (var i = 0; i < t; i++) {
  const n = readline();
  const k = readline();
  if (k >= parseInt((n + 1) / 2))
    print(-1);
  else {
    var a = [];
    var j = 1;
    for ( ; j <= parseInt(n / 2); j++) {
      a.push(j);
      a.push(n - j + 1);
    }
    if (n % 2)
      a.push(j);
    a.forEach(num => print(num));
  }
}


read = +readline();
var pts = readline().split(' ').map(Number);
var max = pts[0];
var min = pts[0];
var ct = 0;
for (var i = 1; i < pts.length; i++) {
				 if(pts[i] > max)
				 			 ct++,max=pts[i];
				 if(pts[i] < min)
				 			 ct++,min=pts[i];
}
write(ct);

var n=+readline();

var a=readline().split(' ').map(function(v){return +v;});

var min=a[0];
var max=a[0];
var ans=0;
for(var i=1; i<n; i++){
	if(a[i]>max){
		ans++;
		max=a[i];
	}else if(a[i]<min){
		ans++;
		min=a[i];
	}
}
print(ans);

var n = +readline(), challenges = readline().split(" "), min = +challenges[0], max = +challenges[0], a = 0;

for(i = 1; i < n; i++){
	if(+challenges[i] > max){
		max = +challenges[i];
		a++;
	}
	else if(+challenges[i] < min){
		min = +challenges[i];
		a++;
	}
}

write(a);

var num = parseInt(readline());
var nums = readline().split(' ').map( function(a) {return parseInt(a);} );
var min = nums[0]; var max = nums[0];
var res = 0;
for (var i = 1; i < num; i++) {
    if (nums[i] > max) {
        res++;
        max = nums[i];
    } else if (nums[i] < min) {
        res++;
        min = nums[i];
    }
}
print(res);

;(function () {

	var n = +readline();
	var s = readline().split(' ').map(function (x) { return parseInt(x); });
	var x = 0;
	var min = s[x];
	var max = s[x];

	for (var i = 1; i < n; i++)
		if ( min > s[i] ) {
			x++;
			min = s[i];
		} else if ( max < s[i] ) {
			x++;
			max = s[i];
		}

	print(x);

}).call(this);

'use strict'

String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

(function () {
  readline();
  let array = readline().getNumArray(),
      min = array[0],
      max = array[0],
      counter = 0;

  for (let i = 1; i < array.length; i++) {
    if (array[i] > max) {
      max = array[i];
      counter++;
    } else if (array[i] < min) {
      min = array[i];
      counter++;
    }
  }
  write(counter);
})();

	var n = readline();//readline().split(" ");
	var str = readline().split(" ");
	var max = +str[0], min = +str[0];
	var res = 0;
	for (var i=0; i<+n; i++){
		if (+str[i]>max){
			max = +str[i];
			res++;
		}
		else if (+str[i]<min){
			min = +str[i];
			res++;
		}
	}
	print(res);

var n = Number(readline());
s = readline().split(' ').map(Number);

var curMax = s[0];
var curMin = s[0];
var miracle = 0;

for (var i = 1; i < s.length; i++) {
    if (s[i] > curMax) {
        miracle++;
        curMax = s[i];
    }
    if (s[i] < curMin){
        miracle++;
        curMin = s[i];
    }
}

print(miracle);

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  const len = +readLine();
  const arr = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  let [max, min] = [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER];
  let count = 0;

  for (let i = 0; i < len; i++) {
    if (i > 0) {
      if (arr[i] > max) count++;
      if (arr[i] < min) count++;
    }
    max = Math.max(max, arr[i]);
    min = Math.min(min, arr[i]);
  }
  console.log(count);
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var min = list[0];
  var max = list[0];
  var output = 0;
  for(var i = 1; i < N; i++){
    if(min > list[i]){
      min = list[i];
      output++;
    }
    if(max < list[i]){
      max = list[i];
      output++;
    }
  }
  myout(output);
}

//I_love_%username%

const {EOL} = require('os');

let inp = '';

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

process.stdin.on('end', () => {
    let lines = inp.split(EOL)[1].split(' ').map(c => +c);

    let max = lines[0], min = lines[0];
    let amazcount = 0;
    for(let i = 1; i < lines.length; i++)  {
    	if(lines[i] > max)  {
    		max = lines[i];
    		amazcount++;
    	}
    	if(lines[i] < min)  {
    		min = lines[i];
    		amazcount++;
    	}
    }

    process.stdout.write(amazcount + '');

    return;
});

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  let ans = 0;
  const res = d.split(' ').map(Number);
  let min = max = res[0];

  for (let i = 0; i < res.length; i++) {
    if (res[i] < min) {
      ans++;
      min = res[i];
    }

    if (res[i] > max) {
      ans++;
      max = res[i];
    }
  }

  console.log(ans);

  c++;
});

n = +readline();
        numbers = [];
        tokens = readline().split(' ');
        for (i = 0; i < n; i++) {
            numbers[i] = +tokens[i];
        }

        max = numbers[0];
        min = numbers[0];
        amazing = 0;

        for (i = 0; i < n; i++) {
            if (numbers[i] > max) {
                max = numbers[i];
                amazing++;
            }
            if (numbers[i] < min) {
                min = numbers[i];
                amazing++;
            }
        }
        print(amazing);

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let nums = input[1].split(' ').map(x => parseInt(x));
  let min = nums[0], max = nums[0];

  let answ = 0;
  nums.forEach((x, i) => {
    if (i === 0) return;

    if (x > max) { answ += 1; max = x; }
    if (x < min) { answ += 1; min = x; }
  });

  console.log(answ);
});

var temporary = readline();
var inputedNumbers = readline().split(' ');
var resultArray = [];
var marksQuantity = 0;

inputedNumbers.forEach(
    function(current)
    {
        current = +current;
        if (current > getArrayMaximum(resultArray) || current < getArrayMinimum(resultArray))
            {
                marksQuantity++;
                }
        resultArray.push(current);
        });
print(marksQuantity-1);

function getArrayMaximum(array)
{
    return Math.max.apply(null, array);
    }

function getArrayMinimum(array)
{
    return Math.min.apply(null, array);
    }

n = readline().split(' ').map(Number);
results = readline().split(' ').map(Number);
min = max = results[0];
amazingness = 0;
for (i = 1; i< results.length; i++){
	if (results[i]<min){
		min = results[i];
		amazingness++;
	}
	else if (results[i]>max){
		max = results[i];
		amazingness++;
	}
}
print(amazingness);

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

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

function isPrime(x) {
	let s = Math.sqrt(x);
	let i = 2;
	while (i <= s) {
		if (x % i === 0) {
			return false;
		}
		i++;
	}
	return true;
}

function main() {
	let n = readLine() >> 0;
	let points = readLine()
		.split(' ')
		.map(x => x >> 0);

	let worse = points[0];
	let best = points[0];
	let amazing = 0;

	for (let i = 1; i < n; ++i) {
		if (points[i] < worse) {
			worse = points[i];
			amazing++;
		}
		if (points[i] > best) {
			best = points[i];
			amazing++;
		}
	}

	console.log(amazing);
}

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 numberOfContests = parseInt(readLine());
    let numbersArray = readLine().split(' ').map(Number);
    let max = numbersArray[0];
    let min = numbersArray[0];
    let count = 0;
    for (let i = 0; i < numberOfContests; i++) {
        if (numbersArray[i] > max) {
            max = numbersArray[i];
            count++;
        }

        if (numbersArray[i] < min) {
            count++;
            min = numbersArray[i];
        }
    }

    console.log(count);
}

// [100, 50, 200, 150, 200]

// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {

    let inputs = str.trim().split('\n');
    let points = inputs[1].trim().split(' ').map(num => Number(num));
    let amazingPoints = 0;
    let best = worst = points[0];
    for (let index = 1; index <= points.length - 1; index++) {

        if (points[index] > best) {
            best = points[index];
            amazingPoints++;
        }

        if (points[index] < worst) {
            worst = points[index];
            amazingPoints++;
        }
    }

    return amazingPoints.toString();
}

'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 = readLine().split(' ').map(v => parseInt(v));
    let best = arr[0];
    let worst = arr[0];
    let ans = 0;
    for (var i = 1; i < n; i++) {
        if (arr[i] > best) {
            ans++;
            best = arr[i];
        }
        if (arr[i] < worst) {
            ans++;
            worst = arr[i];
        }
    }
    console.log(ans);
}

readline()
T=readline().split(' ').map(Number)
print(T.slice(1).reduce((a,c)=>{
	a.a += Number(c<a.lb || a.ub<c)
	a.ub=Math.max(a.ub,c)
	a.lb=Math.min(a.lb,c)
	return a;
}, {lb:T[0],ub:T[0],a:0}).a)

var numberCompetitions = +readline();
var tableResult = readline().split(" ");
var maxPoint = +tableResult[0];
var minPoint = +tableResult[0];
var amazingPerfomance = 0;
for (var perfomance=0; perfomance<numberCompetitions; perfomance++) {
    if (+tableResult[perfomance]<minPoint) {
        minPoint = +tableResult[perfomance];
        amazingPerfomance++;
    } else if (+tableResult[perfomance]>maxPoint) {
        maxPoint = +tableResult[perfomance];
        amazingPerfomance++;
    }
}
print(amazingPerfomance);

var n=+readline();

var a=readline().split(' ').map(function(v){return +v;});

var min=a[0];
var max=a[1];
var ans=0;
for(var i=1; i<n; i++){
	if(a[i]>max){
		ans++;
		max=a[i];
	}else if(a[i]<min){
		ans++;
		min=a[i];
	}
}
print(ans);

var n = readline();
var str = readline().split(" ");
var min =0; var max = 0;
if (+str[0]>+str[1]) {max=+str[0] ; min=+str[1];} else {max=+str[1], min=+str[0];}
var res = 1;
	for (var i=2; i<n; i++){

		 if (str[i]>max)
		 {
				res++;
				max = +str[i];
		 }
		 else if (str[i]<min){
				res++;
				min = +str[i];
		 }
	}
	str.length>1?print(res):print(0);

var n = readline();
var str = readline().split(" ");
var min =0; var max = 0;
if (+str[0]>+str[1]) {max=+str[0] ; min=+str[1];} else {max=+str[1], min=+str[0];}
var res = 1;
	for (var i=2; i<n; i++){

		 if (str[i]>max)
		 {
				res++;
				max = +str[i];
		 }
		 else if (str[i]<min){
				res++;
				min = +str[i];
		 }
	}
	print(res);

var n = Number(readline());
s = readline().split(' ').map(Number);

var cur = [s[0]];
var miracle = 0;

for (var i = 0; i < s.length; i++) {
    if (s[i] > cur[i] || s[i] < cur[i]) {
        miracle++;
    }
    cur.push(s[i]);
}

print(Math.floor(miracle/2));

read = +readline();
var pts = readline().split(' ');
var max = pts[0];
var min = pts[0];
var ct = 0;
pts.shift();
pts.map(function(c){
				if( c > max )
							ct++,max=c;
				else
							ct++,min=c;
});
write(ct);

read = +readline();
var pts = readline().split(' ');
var max = pts[0];
var min = pts[0];
var ct = 0;
pts.shift();
pts.map(function(c){
				if( c > max )
							ct++,max=c;
				if( c < min )
							ct++,min=c;
});
write(ct);


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

let gcd = (a, b) => a ? gcd(b % a, a) : b;
let lcm = (a, b) => a * b / gcd(a, b);

function main(){

    let n = readLine();
    let lights = readLine().split('').map( x => parseInt(x));
    // console.log(lights);
    var dur = [];
    var del = [];
    for(let i=0; i< n ; ++i){
        let tmp = readLine().split(' ').map( x => parseInt(x));
        dur.push(tmp[0]);
        del.push(tmp[1]);
    }
    // console.log(dur);
    // console.log(del);

     // var l=del.reduce(lcm)
     // console.log(l)
    var c =[];
    for(let i=0;i<2000;++i){
        c[i]=0;
    }

    for(let i=0;i<n;++i ){
        for(let j=0;j<1000;){
            while(j<del[i]){
                c[j++]+=lights[i];
            }

            if(lights[i]){
                j+=dur[i];
                for(let k=0;k<dur[i];++k){
                    c[j++]+=1;
                }
            }

            else{
                for(let k=0;k<dur[i];++k){
                    c[j++]+=1;
                }
                j+=dur[i];
            }
        }
    }
    // console.log(c);
    console.log(Math.max(...c));

}

let i = '';
process.stdin.on('data', (c) => {
  i += c;
});
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = i.split(EOL);
  const initialState = lines[1];
  const tuples = [];
  for (let i = 2; i < lines.length; i++) {
    let tuple = lines[i].split(' ');
    if (tuple.length === 2) {
      tuple = tuple.map(num => parseInt(num, 10));
      tuples.push(tuple);
    }
  }
  maxLights(initialState, tuples);
});

function maxLights(initial, tuples) {
  let split = initial.split('');
  let states = [];
  for (let i = 0; i < tuples.length; i++) {
    let statesForI = [];
    const [a, b] = tuples[i];

    let state = split[i] === '1';
    for (let j = 0; j < b; j++) {
      statesForI.push(state);
    }

    state = !state;

    let count = 0;
    for (let j = b; j < 125; j++) {
      if (count === a) {
        state = !state;
        count = 0;
      }
      count++;
      statesForI.push(state);
    }

    states.push(statesForI.slice());
  }

  let max = 0;
  for (let i = 0; i < 125; i++) {
    let count = 0;
    states.forEach(state => {
      if (state[i]) count++;
    });
    max = Math.max(count, max);
  }
  console.log(max);
  return max;
}

"use strict";

String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

var n = readline().getNumArray()[0];
var defaultState = readline().split('').map(function (value) {
  return parseInt(value);
});
var data = [];

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

var period = 0;
var periodStarted = 1;

var toggleLight = function toggleLight(state) {
  if (state === 0) {
    return 1;
  }

  return 0;
};

var checkLight = function checkLight(second, indexOfLight) {
  var periods = parseInt((second - data[indexOfLight][periodStarted]) / data[indexOfLight][period] + 1);
  var stateChanged = periods % 2 === 1;

  if (stateChanged) {
    return toggleLight(defaultState[indexOfLight]);
  }

  return defaultState[indexOfLight];
};

var amountOfLights = 0;

for (var _i = 0; _i <= 1200; _i++) {
  var lights = 0;

  for (var lightIndex = 0; lightIndex < n; lightIndex++) {
    lights += checkLight(_i, lightIndex);
  }

  if (lights > amountOfLights) {
    amountOfLights = lights;
  }
}

write(amountOfLights);

var elements = parseInt(readline());
var initial = readline();
var current = initial
var pairs = []
for (var i = 0; i < elements; i++) {
  pairs.push(readline().split(' ').map(function(num) {
    return parseInt(num);
  }))
}

var maxLights = function(lights) {
  return lights.split('').map(function(num) {
    return parseInt(num);
  }).reduce(function(acc, num) {
    return acc + num;
  }, 0);
}

var max = maxLights(initial);

var uniques = []
for (var i = 0; i < pairs.length; i++) {
  uniques.push(pairs[i][1])
}
uniques = Array.from(new Set(uniques))
uniques = uniques.reduce(function(acc, num) {
  return acc*num;
}, 1);

function foo() {
  var step = 0;
  while (step < 10000) {
    step++;
    for (var i = 0; i < pairs.length; i++) {
      if (step - pairs[i][1] < 0)
        continue;
      if ((step - pairs[i][1]) % pairs[i][0] === 0) {
        current = current.split('')
        current[i] = (current[i] === '0') ? '1' : '0'
        current = current.join('')
      }
    }
    max = Math.max(max, maxLights(current))
  }

  write(max)
}

foo();

"use strict";

String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

var n = readline().getNumArray()[0];
var defaultState = readline().split('').map(function (value) {
  return parseInt(value);
});
var data = [];

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

var period = 0;
var periodStarted = 1;

var toggleLight = function toggleLight(state) {
  if (state === 0) {
    return 1;
  }

  return 0;
};

var checkLight = function checkLight(second, indexOfLight) {
  var periods = (second - data[indexOfLight][periodStarted]) / data[indexOfLight][period] + 1;
  var stateChanged = periods % 2 === true;

  if (stateChanged) {
    return toggleLight(defaultState[indexOfLight]);
  }

  return defaultState[indexOfLight];
};

var amountOfLights = 0;

for (var _i = 1; _i <= 120; _i++) {
  var lights = 0;

  for (var lightIndex = 0; lightIndex < n; lightIndex++) {
    lights += checkLight(_i, lightIndex);
  }

  if (lights > amountOfLights) {
    amountOfLights = lights;
  }
}

write(amountOfLights);

"use strict";

String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

var n = readline().getNumArray()[0];
var defaultState = readline().split('').map(function (value) {
  return parseInt(value);
});
var data = [];

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

var period = 0;
var periodStarted = 1;

var toggleLight = function toggleLight(state) {
  if (state === 0) {
    return 1;
  }

  return 0;
};

var checkLight = function checkLight(second, indexOfLight) {
  var periods = parseInt((second - data[indexOfLight][periodStarted]) / data[indexOfLight][period] + 1);
  var stateChanged = periods % 2 === 1;

  if (stateChanged) {
    return toggleLight(defaultState[indexOfLight]);
  }

  return defaultState[indexOfLight];
};

var amountOfLights = 0;

for (var _i = 1; _i <= 500; _i++) {
  var lights = 0;

  for (var lightIndex = 0; lightIndex < n; lightIndex++) {
    lights += checkLight(_i, lightIndex);
  }

  if (lights > amountOfLights) {
    amountOfLights = lights;
  }
}

write(amountOfLights);

var elements = parseInt(readline());
var initial = readline();
var current = initial
var pairs = []
for (var i = 0; i < elements; i++) {
  pairs.push(readline().split(' ').map(function(num) {
    return parseInt(num);
  }))
}

// var initial = '101'
// var current = initial;
// var pairs = [[3, 3], [3, 2], [3, 1]]

var maxLights = function(lights) {
  return lights.split('').map(function(num) {
    return parseInt(num);
  }).reduce(function(acc, num) {
    return acc + num;
  }, 0);
}

var max = maxLights(initial);

var uniques = []
for (var i = 0; i < pairs.length; i++) {
  uniques.push(pairs[i][1])
}
uniques = Array.from(new Set(uniques))
uniques = uniques.reduce(function(acc, num) {
  return acc*num;
}, 1);

function foo() {
  var step = 0;
  while (initial !== current || step < pairs[0][1]) {
    if (step > uniques) {
      write(max);
      return;
    }
    step++;
    for (var i = 0; i < pairs.length; i++) {
      if (step - pairs[i][1] < 0)
        continue;
      if ((step - pairs[i][1]) % pairs[i][0] === 0) {
        current = current.split('')
        current[i] = (current[i] === '0') ? '1' : '0'
        current = current.join('')
      }
    }
    max = Math.max(max, maxLights(current))
  }

  write(max)
}

foo();


var n = +readline();
var array = [], check = true;

for(i = 0; i < n; i++){
	array.push(readline().split(""));
}

for(i = 0; i < n; i++){
	for(j = 0; j < n; j++){
		cnt = 0;
		if(array[i][j-1] == "o"){
			cnt++;
		}
		if(array[i][j+1] == "o"){
			cnt++;
		}
		if(array[i-1] != undefined && array[i-1][j] == "o"){
			cnt++;
		}
		if(array[i+1] != undefined && array[i+1][j] == "o"){
			cnt++;
		}

		if(cnt % 2 != 0){
			check = false;
		}
	}
}

if(check){
	write("YES");
}
else{
	write("NO");
}

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

var i, j, x, y;

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

var count;
var off = [
	[0, 1],
	[0, -1],
	[1, 0],
	[-1, 0]
];

var flag = true;

for (i = 0; i < n; i++) {
	for (j = 0; j < n; j++) {
		count = 0;
		for (k = 0; k < off.length; k++) {
			x = j + off[k][1];
			y = i + off[k][0];
			if (x >= 0 && y >= 0 && x < n && y < n)
				if (map[y].charAt(x) == 'o')
					count++;
		}
		if (count % 2 != 0) {
			flag = false;
			break;
		}
	}
}

write(flag?'YES':'NO');

var n = parseInt(readline());
var allEven = true;
var board = [];

for (var i = 0; i < n; i++) {
  board[i] = readline();
}

out: for (var i = 0; i < n; i++) {
  for (var j = 0; j < n; j++) {
    if (check(board, i, j) % 2 != 0) {
      allEven = false;
      break out;
    }
  }
}

if (allEven) {
  print("YES");
} else {
  print("NO");
}

function check(arr, i, j) {
  var rows = arr.length;
  var cols = arr[0].length;
  var countOfO = 0;

  if (i != 0) {
    if (arr[i - 1][j] =='o') {
      countOfO++;
    }
  }

  if (i != rows - 1) {
    if (arr[i + 1][j] =='o') {
      countOfO++;
    }
  }

  if (j != 0) {
    if (arr[i][j - 1] =='o') {
      countOfO++;
    }
  }

  if (j != cols - 1) {
    if (arr[i][j + 1] =='o') {
      countOfO++;
    }
  }

  return countOfO;
}

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var n = parseInt(readline()),
		board = [];
	for (var i = 0; i < n; ++i) {
		var line = trim(readline());
		board.push([]);
		for (var j = 0; j < n; ++j) {
			board[i].push(line.charAt(j));
		}
	}
	var di = [-1, 0, 1, 0], dj = [0, 1, 0, -1];
	for (var i = 0; i < n; ++i) {
		for (var j = 0; j < n; ++j) {
			var count = 0;
			for (var k = 0; k < 4; ++k) {
				var I = i+di[k], J = j+dj[k];
				if (I < 0 || I == n || J < 0 || J == n) {
					continue;
				}
				if (board[I][J] == 'o') {
					++count;
				}
			}
			if (count%2 == 1) {
				print('NO');
				return;
			}
		}
	}
	print('YES');
}

main();

var lineNumber = readline();
var lines = [];
for(var i=0; i<lineNumber; i++){
    var  line = readline();
    lines.push(line);
}

(function(){
    for(var i=0; i<lineNumber; i++){
        var line = lines[i];
        for(var j=0, jLength=line.length; j<jLength; j++){
            var oNum = 0;
            var cell = line[j];
            var left = line[j-1];
            var right = line[j+1];
            var top = lines[i-1] ? lines[i-1][j] : false;
            var bottom = lines[i+1] ? lines[i+1][j] : false ;

            if(left && left=='o') oNum++;
            if(right && right=='o') oNum++;
            if(top && top=='o') oNum++;
            if(bottom && bottom=='o') oNum++;

            if(oNum%2 != 0){
                print('NO');
                return;
            }

        }
    }

    print('YES');
})();

var n = parseInt(readline());
var arr = [];
for (var i=0; i<n; i++) {
arr.push(readline().trim().toLowerCase().split(""));
}

var even = true;
var c;
for (var i=0; i<n; i++) {
for (var j=0; j<n; j++) {
c = 0;
if (i>0 && arr[i-1][j]=="o") c++;
if (i<n-1 && arr[i+1][j]=="o") c++;
if (j>0 && arr[i][j-1]=="o") c++;
if (j<n-1 && arr[i][j+1]=="o") c++;

if (c%2==1) even = false;
}
}

print(even?"YES":"NO");

var n = readline().replace(/\s{1,}/gi, ' ').split(/\s/).map(Number),
			board = [],
			result = true;

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

		for(var y=0; y<n; y++)	{
			var row = board[y],
				prevRow = board[y - 1] == undefined ? [] : board[y - 1],
				nextRow = board[y + 1] == undefined ? [] : board[y + 1];

			for(var x=0; x<n; x++)	{
				var ch = row[x];

				var tempArr = [ row[x - 1], row[x + 1], prevRow[x], nextRow[x] ];

				tempArr = tempArr.map(function(a)	{
					return a == 'o' ? 1 : 0;
				});

				if(tempArr.reduce(function(a, b) { return a + b; }) % 2 != 0)	{
					result = false;

					break;
				}
			}

			if(!result)	break;
		}

		print(result ? 'YES' : 'NO');

function gao()
{
    var offset = [[-1,0],[1,-0],[0,-1],[0,1]];

    var n = readline();
	var map = new Array();
	for( var i = 0; i < n; i++ )
	{
	    map[i] = readline().split("");
	}

	var result = 'YES';
	for(var i=0; i<n; i++)
	{
	    for(var j=0; j<n; j++)
		{
		    var num =0;
			for(var k in offset)
			{
			    if( typeof(map[ offset[k][0] + i ]) != 'undefined' &&
				    map[ offset[k][0] + i ][ offset[k][1] + j ] == "o")
				{
				    num++;
				}
			}
			if((num%2)==1)
			{
			    result = "NO";
			}

		}
	}
	print(result);
}

gao();

function gao()
{
    var offset = [[-1,1],[-1,-1],[1,-1],[1,1]];

    var n = readline();
	var map = new Array();
	for( var i = 0; i < n; i++ )
	{
	    map[i] = readline().split("");
	}

	var result = 'YES';
	for(var i=0; i<n; i++)
	{
	    for(var j=0; j<n; j++)
		{
		    var num =0;
			for(var k=0; k<4; k++)
			{
			    if( typeof(map[ offset[k][0] + i ]) != 'undefined' &&
				    map[ offset[k][0] + i ][ offset[k][1] + j ] == "o")
				{
				    num++;
				}
			}
			if((num%2)==1)
			{
			    result = "NO";
			}
		}
	}
	print(result);
}

gao();