Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wanted to give her an affectionate gift but couldn't think of anything inventive. Hence, he will be giving her a graph. How original, Bob! Alice will surely be thrilled!When building the graph, he needs four conditions to be satisfied:   It must be a simple undirected graph, i.e. without multiple (parallel) edges and self-loops.  The number of vertices must be exactly $$$n$$$ — a number he selected. This number is not necessarily prime.  The total number of edges must be prime.  The degree (i.e. the number of edges connected to the vertex) of each vertex must be prime. Below is an example for $$$n = 4$$$. The first graph (left one) is invalid as the degree of vertex $$$2$$$ (and $$$4$$$) equals to $$$1$$$, which is not prime. The second graph (middle one) is invalid as the total number of edges is $$$4$$$, which is not a prime number. The third graph (right one) is a valid answer for $$$n = 4$$$.   Note that the graph can be disconnected.Please help Bob to find any such graph!

The input consists of a single integer $$$n$$$ ($$$3 \leq n \leq 1\,000$$$) — the number of vertices.

If there is no graph satisfying the conditions, print a single line containing the integer $$$-1$$$. Otherwise, first print a line containing a prime number $$$m$$$ ($$$2 \leq m \leq \frac{n(n-1)}{2}$$$) — the number of edges in the graph. Then, print $$$m$$$ lines, the $$$i$$$-th of which containing two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$) — meaning that there is an edge between vertices $$$u_i$$$ and $$$v_i$$$. The degree of each vertex must be prime. There must be no multiple (parallel) edges or self-loops. If there are multiple solutions, you may print any of them. Note that the graph can be disconnected.

NoteThe first example was described in the statement.In the second example, the degrees of vertices are $$$[7, 5, 2, 2, 3, 2, 2, 3]$$$. Each of these numbers is prime. Additionally, the number of edges, $$$13$$$, is also a prime number, hence both conditions are satisfied.

"use strict";

var main = function() {
    var n = +rd();
    var S = crAr(2000, true);
    for (var i = 2; i < S.length; ++i) {
        for (var j = i+i; j < S.length; j += i) {
            S[j] = false;
        }
    }
    var p = null;
    for (var i = 2; i < S.length; ++i) {
        if (S[i] && i >= n) {
            p = i;
            break;
        }
    }
    pr(p);
    var d = p - n;
    for (var i = 1; i < n; ++i) {
        pr(i, i + 1);
    }
    pr(1, n);
    for (var i = 1; i <= d; ++i) {
        pr(i, n - i);
    }
};

const rd = readline;
const wr = write;
const pr = print;
const rdAr = () => rd().split(' ').map(v => +v);
const prAr = (a) => pr(a.join(' '));
const cmpLt = (a, b) => a - b;
const cmpGt = (a, b) => b - a;
Array.prototype.sortLt = function() { return this.sort(cmpLt); };
Array.prototype.sortGt = function() { return this.sort(cmpGt); };
const crAr = function(length, ...fillArgs) { return new Array(length).fill(...fillArgs); };

main();

"use strict";

var main = function() {
    wr('3\n1 2\n2 3\n1 3');
};

const rd = readline;
const wr = write;
const pr = print;
const rdAr = () => rd().split(' ').map(v => +v);
const prAr = (a) => pr(a.join(' '));
const cmpLt = (a, b) => a - b;
const cmpGt = (a, b) => b - a;
Array.prototype.sortLt = function() { return this.sort(cmpLt); };
Array.prototype.sortGt = function() { return this.sort(cmpGt); };
const crAr = function(length, ...fillArgs) { return new Array(length).fill(...fillArgs); };

main();

"use strict";

var main = function() {
    var n = +rd();
    var S = crAr(2000, true);
    for (var i = 2; i < S.length; ++i) {
        for (var j = i+i; j < S.length; j += i) {
            S[j] = false;
        }
    }
    var p = null;
    for (var i = 2; i < S.length; ++i) {
        if (S[i] && i > n) {
            p = i;
            break;
        }
    }
    pr(p);
    var d = p - n;
    for (var i = 1; i < n; ++i) {
        pr(i, i + 1);
    }
    pr(1, n);
    for (var i = 1; i <= d; ++i) {
        pr(i, n - i);
    }
};

const rd = readline;
const wr = write;
const pr = print;
const rdAr = () => rd().split(' ').map(v => +v);
const prAr = (a) => pr(a.join(' '));
const cmpLt = (a, b) => a - b;
const cmpGt = (a, b) => b - a;
Array.prototype.sortLt = function() { return this.sort(cmpLt); };
Array.prototype.sortGt = function() { return this.sort(cmpGt); };
const crAr = function(length, ...fillArgs) { return new Array(length).fill(...fillArgs); };

main();


Ilya lives in a beautiful city of Chordalsk.There are $$$n$$$ houses on the street Ilya lives, they are numerated from $$$1$$$ to $$$n$$$ from left to right; the distance between every two neighboring houses is equal to $$$1$$$ unit. The neighboring houses are $$$1$$$ and $$$2$$$, $$$2$$$ and $$$3$$$, ..., $$$n-1$$$ and $$$n$$$. The houses $$$n$$$ and $$$1$$$ are not neighboring.The houses are colored in colors $$$c_1, c_2, \ldots, c_n$$$ so that the $$$i$$$-th house is colored in the color $$$c_i$$$. Everyone knows that Chordalsk is not boring, so there are at least two houses colored in different colors.Ilya wants to select two houses $$$i$$$ and $$$j$$$ so that $$$1 \leq i < j \leq n$$$, and they have different colors: $$$c_i \neq c_j$$$. He will then walk from the house $$$i$$$ to the house $$$j$$$ the distance of $$$(j-i)$$$ units.Ilya loves long walks, so he wants to choose the houses so that the distance between them is the maximum possible.Help Ilya, find this maximum possible distance.

The first line contains a single integer $$$n$$$ ($$$3 \leq n \leq 300\,000$$$) — the number of cities on the street. The second line contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \leq c_i \leq n$$$) — the colors of the houses. It is guaranteed that there is at least one pair of indices $$$i$$$ and $$$j$$$ so that $$$1 \leq i < j \leq n$$$ and $$$c_i \neq c_j$$$.

Print a single integer — the maximum possible distance Ilya can walk.

NoteIn the first example the optimal way is to walk from the first house to the last one, where Ilya can walk the distance of $$$5-1 = 4$$$ units.In the second example the optimal way is to either walk from the first house to the second or from the second to the third. Both these ways have the distance of $$$1$$$ unit.In the third example the optimal way is to walk from the third house to the last one, where Ilya can walk the distance of $$$7-3 = 4$$$ units.

var len = parseInt(readline());
var houseArr = readline().split(' ').map(_ => {return parseInt(_);});
var maxDis = 0;
for (var i = 0;i < len;i ++) {
    var house = houseArr[i];
    var dispre = i;
    var dissuf = len - i - 1;
    if (house != houseArr[0] && dispre > maxDis) {
        maxDis = dispre;
    }
    if (house != houseArr[len - 1] && dissuf > maxDis) {
        maxDis = dissuf;
    }
}
print(maxDis);

var len = parseInt(readline());
var houseArr = readline().split(' ').map(_ => {return parseInt(_);});
var maxDis = 0;
for (var i = 0;i < len;i ++) {
    for(var j = len - 1;j > i; j --) {
        var distance = j - i;
        if (distance > maxDis) {
            maxDis = distance;
        }
    }
}
print(maxDis);

var len = parseInt(readline());
var houseArr = readline().split(' ').map(_ => {return parseInt(_);});
var maxDis = 0;
for (var i = 0;i < len;i ++) {
    var house = houseArr[i];
    var dispre = i;
    var dissuf = len - i;
    if (house != houseArr[0] && dispre > maxDis) {
        maxDis = dispre;
    }
    if (house != houseArr[len - 1] && dissuf > maxDis) {
        maxDis = dissuf;
    }
}
print(maxDis);


Alice and Bob are playing a fun game of tree tag.The game is played on a tree of $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$. Recall that a tree on $$$n$$$ vertices is an undirected, connected graph with $$$n-1$$$ edges.Initially, Alice is located at vertex $$$a$$$, and Bob at vertex $$$b$$$. They take turns alternately, and Alice makes the first move. In a move, Alice can jump to a vertex with distance at most $$$da$$$ from the current vertex. And in a move, Bob can jump to a vertex with distance at most $$$db$$$ from the current vertex. The distance between two vertices is defined as the number of edges on the unique simple path between them. In particular, either player is allowed to stay at the same vertex in a move. Note that when performing a move, a player only occupies the starting and ending vertices of their move, not the vertices between them.If after at most $$$10^{100}$$$ moves, Alice and Bob occupy the same vertex, then Alice is declared the winner. Otherwise, Bob wins.Determine the winner if both players play optimally.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains five integers $$$n,a,b,da,db$$$ ($$$2\le n\le 10^5$$$, $$$1\le a,b\le n$$$, $$$a\ne b$$$, $$$1\le da,db\le n-1$$$)  — the number of vertices, Alice's vertex, Bob's vertex, Alice's maximum jumping distance, and Bob's maximum jumping distance, respectively. The following $$$n-1$$$ lines describe the edges of the tree. The $$$i$$$-th of these lines contains two integers $$$u$$$, $$$v$$$ ($$$1\le u, v\le n, u\ne v$$$), denoting an edge between vertices $$$u$$$ and $$$v$$$. It is guaranteed that these edges form a tree structure. It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$10^5$$$.

For each test case, output a single line containing the winner of the game: "Alice" or "Bob".

NoteIn the first test case, Alice can win by moving to vertex $$$1$$$. Then wherever Bob moves next, Alice will be able to move to the same vertex on the next move.  In the second test case, Bob has the following strategy to win. Wherever Alice moves, Bob will always move to whichever of the two vertices $$$1$$$ or $$$6$$$ is farthest from Alice.

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

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return mid;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  let sub = [];
  a = a || 0;
  b = b || (this.length - 1);
  for (let i = a; i <= b; i++) {
    sub.push(this[i])
    if (fn(this[i], i, this)) {
      arr.push(sub);
      sub = [];
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
let MOD = 998244353
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + MOD) % MOD;
}

// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

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

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let [n, a, b, da, db] = $(5)
    let e = Arr(n + 1, i => [])
    let u, v
    For(n - 1, i => {
      u = $(), v = $()
      e[u].push(v)
      e[v].push(u)
    })
    // log(e)
    if (da >= db / 2) { log('Alice'); continue }

    let t = 1;
    let mark = Array(n + 1).fill(0)
    let dfs = async (u, d) => {
      if (t++ % 1000 == 0) await Promise.resolve();
      if (mark[u]) return;
      mark[u] = d;
      for (let v of e[u]) await dfs(v, d + 1);
    }
    await dfs(a, 1)
    // log(mark)
    if (da >= mark[b] - 1) { log('Alice'); continue }
    let idm = mark.max()[1];
    mark.fill(0)
    await dfs(idm, 1);
    // log(mark)
    if (da >= (mark.max()[0] - 1) / 2) { log('Alice'); continue }
    log('Bob')
  }
}

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

    D();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function D(){

    let t = pi(readline());

    while(t > 0){
        t--;
        let [n,a,b,da,db] = ti(readline().split(' '));

        let adj = new Array(n);
        for(let i = 0; i < n; i++)
            adj[i] = [];

        for(let i = 0; i < n-1; i++){
            let [u,v] = ti(readline().split(' '));
            adj[u-1].push(v-1);
            adj[v-1].push(u-1);
        }

        let dist = new Array(n);
        let bfs = (st, n) => {
            let q = [st,null];
            let level = 0;
            let v = new Array(n);
            v.fill(false);
            dist.fill(-1);
            while(q.length > 0){
                let node = q.shift();
                if(node !== null){
                    v[node] = true;
                    dist[node] = level;
                    for(let i = 0; i < adj[node].length; i++){
                        if(!v[adj[node][i]])
                            q.push(adj[node][i]);
                    }
                }else{
                    level += 1;
                    if(q.length > 0)
                        q.push(null);
                }
            }
        }

        let farthest = (dist) => {
            let max = -1;
            let ans = -1;
            for(let i = 0; i < dist.length; i++){
                if(dist[i] > max){
                    max = dist[i];
                    ans = i;
                }
            }

            return ans;
        }

        bfs(a-1, n);
        if(dist[b-1] <= da){
            console.log('Alice');
            continue;
        }
        let f = farthest(dist);
        bfs(f, n);
        let ff = farthest(dist);
        let diameter = dist[ff];

        if(da*2 >= db){
            console.log('Alice');
            continue;
        }

        if(diameter <= da*2){
            console.log('Alice');
            continue;
        }

        console.log('Bob');
    }
}

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

    D();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function D(){

    let t = pi(readline());

    while(t > 0){
        t--;
        let [n,a,b,da,db] = ti(readline().split(' '));

        let adj = new Array(n);
        for(let i = 0; i < n; i++)
            adj[i] = [];

        for(let i = 0; i < n-1; i++){
            let [u,v] = ti(readline().split(' '));
            adj[u-1].push(v-1);
            adj[v-1].push(u-1);
        }

        let queue = [a-1, null];
        let visited = new Array(n);
        visited.fill(false);
        let dab = 0;
        while(queue.length > 0){
            let node = queue.shift();
            if(node !== null){
                visited[node] = true;
                if(node === b-1)
                    break;

                for(let i = 0; i < adj[node].length; i++){
                    if(!visited[adj[node][i]])
                        queue.push(adj[node][i]);
                }
            }else{
                dab += 1;
                if(queue.length > 0)
                    queue.push(null);
            }
        }

        if(dab <= da){
            console.log('Alice');
            continue;
        }

        let bfs = (st, n, en) => {
            let q = [st,null];
            let level = 0;
            let v = new Array(n);
            v.fill(false);
            while(q.length > 0){
                let node = q.shift();
                if(node !== null){
                    v[node] = true;
                    en.val = node;
                    for(let i = 0; i < adj[node].length; i++){
                        if(!v[adj[node][i]])
                            q.push(adj[node][i]);
                    }
                }else{
                    level += 1;
                    if(q.length > 0)
                        q.push(null);
                }
            }

            return level;
        }

        let en = {val: -1};
        bfs(a-1, n, en);
        let diameter = bfs(en.val, n, -1);

        if(da >= Math.ceil(diameter/2)){
            console.log('Alice');
            continue;
        }

        if(da >= Math.ceil(db/2)){
            console.log('Alice');
            continue;
        }

        console.log('Bob');
    }
}

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

    D();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function D(){

    let t = pi(readline());

    while(t > 0){
        t--;
        let [n,a,b,da,db] = ti(readline().split(' '));

        let adj = new Array(n);
        for(let i = 0; i < n; i++)
            adj[i] = [];

        for(let i = 0; i < n-1; i++){
            let [u,v] = ti(readline().split(' '));
            adj[u-1].push(v-1);
            adj[v-1].push(u-1);
        }

        let queue = [a-1, null];
        let visited = new Array(n);
        visited.fill(false);
        let dab = 0;
        while(queue.length > 0){
            let node = queue.shift();
            if(node !== null){
                visited[node] = true;
                if(node === b-1)
                    break;

                for(let i = 0; i < adj[node].length; i++){
                    if(!visited[adj[node][i]])
                        queue.push(adj[node][i]);
                }
            }else{
                dab += 1;
                if(queue.length > 0)
                    queue.push(null);
            }
        }

        if(dab <= da){
            console.log('Alice');
            continue;
        }

        let bfs = (st, n, en) => {
            let q = [st,null];
            let level = 0;
            let v = new Array(n);
            v.fill(false);
            while(q.length > 0){
                let node = q.shift();
                if(node !== null){
                    v[node] = true;
                    en.val = node;
                    for(let i = 0; i < adj[node].length; i++){
                        if(!v[adj[node][i]])
                            q.push(adj[node][i]);
                    }
                }else{
                    level += 1;
                    if(q.length > 0)
                        q.push(null);
                }
            }

            return level;
        }

        let en = {val: -1};
        bfs(a-1, n, en);
        let diameter = bfs(en.val, n, -1);

        if(da*2 >= db){
            console.log('Alice');
            continue;
        }

        if(diameter <= da*2){
            console.log('Alice');
            continue;
        }

        console.log('Bob');
    }
}

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

    D();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function D(){

    let t = pi(readline());

    while(t > 0){
        t--;
        let [n,a,b,da,db] = ti(readline().split(' '));

        let adj = new Array(n);
        for(let i = 0; i < n; i++)
            adj[i] = [];

        for(let i = 0; i < n-1; i++){
            let [u,v] = ti(readline().split(' '));
            adj[u-1].push(v-1);
            adj[v-1].push(u-1);
        }

        let queue = [a-1, null];
        let visited = new Array(n);
        visited.fill(false);
        let dab = 0;
        while(queue.length > 0){
            let node = queue.shift();
            if(node !== null){
                visited[node] = true;
                if(node === b-1)
                    break;

                for(let i = 0; i < adj[node].length; i++){
                    if(!visited[adj[node][i]])
                        queue.push(adj[node][i]);
                }
            }else{
                dab += 1;
                if(queue.length > 0)
                    queue.push(null);
            }
        }

        if(dab <= da){
            console.log('Alice');
            continue;
        }

        let bfs = (st, n, en) => {
            let q = [st,null];
            let level = 0;
            let v = new Array(n);
            v.fill(false);
            while(q.length > 0){
                let node = q.shift();
                if(node !== null){
                    v[node] = true;
                    en.val = node;
                    for(let i = 0; i < adj[node].length; i++){
                        if(!v[adj[node][i]])
                            q.push(adj[node][i]);
                    }
                }else{
                    level += 1;
                    if(q.length > 0)
                        q.push(null);
                }
            }

            return level;
        }

        let en = {val: -1};
        bfs(a-1, n, en);
        let diameter = bfs(en.val, n, {val: -1});

        if(da*2 >= db){
            console.log('Alice');
            continue;
        }

        if(diameter <= da*2){
            console.log('Alice');
            continue;
        }

        console.log('Bob');
    }
}


There is a game called "Unique Bid Auction". You can read more about it here: https://en.wikipedia.org/wiki/Unique_bid_auction (though you don't have to do it to solve this problem).Let's simplify this game a bit. Formally, there are $$$n$$$ participants, the $$$i$$$-th participant chose the number $$$a_i$$$. The winner of the game is such a participant that the number he chose is unique (i. e. nobody else chose this number except him) and is minimal (i. e. among all unique values of $$$a$$$ the minimum one is the winning one).Your task is to find the index of the participant who won the game (or -1 if there is no winner). Indexing is $$$1$$$-based, i. e. the participants are numbered from $$$1$$$ to $$$n$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of participants. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th participant chosen number. It is guaranteed that the sum of $$$n$$$ does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer — the index of the participant who won the game (or -1 if there is no winner). Note that the answer is always unique.

const solve = (n, game) => {
    let map = getRecord2(game);
    let u = game.filter(x => map.get(x) == 1);
    let min = Math.min.apply(Math, u);
    for (let i = 0; i < n; i++) {
        if (game[i] == min && map.get(game[i]) == 1) {
            console.log(i + 1);
            return;
        }
    }
    console.log(-1);
};

const getRecord2 = (arr) => {
    let map = new Map();
    for (const i of arr) {
        map.set(i, (map.get(i) + 1) || 1);
    }
    return map;
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = Number(input[0][0]);
        for (let i = 1; t--; i += 2) {
            solve(input[i], input[i + 1]);
        }
    });
};

main()

const solve = (n, game) => {
    let map = getRecord2(game);
    let u = game.filter(x => map.get(x) == 1);
    let min = Math.min.apply(Math, u);
    for (let i = 0; i < n; i++) {
        if (game[i] == min && map.get(game[i]) == 1) {
            console.log(i + 1);
            return;
        }
    }
    console.log(-1);
};

const getRecord2 = (arr) => {
    let map = new Map();
    for (const i of arr) {
        map.set(i, (map.get(i) + 1) || 1);
    }
    return map;
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = Number(input[0][0]);
        let i = 1;
        while (t > 0) {
            let data = input.slice(i, i + 2);
            solve(data[0][0], data[1]);
            t--;
            i += 2;
        }
    });
};

main()

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine().split(" ").map(Number);
    const map = new Map();

    for (let i = 0; i < len; i++) {
      const n = arr[i];
      if (map.get(n)) {
        map.get(n).count++;
      } else {
        map.set(n, { count: 1, index: i + 1 });
      }
    }
    let [minVal, min] = [Infinity, Infinity];
    for (let [key, obj] of map) {
      const { count, index } = obj;
      if (count === 1 && key < minVal) {
        minVal = key;
        min = index;
      }
    }
    if (min === Infinity) {
      console.log(-1);
    } else {
      console.log(min);
    }
  }
}

//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){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function 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 init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		var map = {};
		for(var j = 0; j < N; j++){
			if(map[list[j]] == null){
				map[list[j]] = [];
			}
			map[list[j]].push(j);
		}
		var key = Object.keys(map);
		key.sort(function(a,b){
			return a - b;
		});
		var ans = -1;
		for(var j = 0; j < key.length; j++){
			if(map[key[j]].length == 1){
				ans = map[key[j]][0] + 1;
				break;
			}
		}
		output[i] = ans;
	}
	myout(myconv(output, 9));
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 2;
    let i = 1;
    while (i <= testCases) {
      const s = data[i + 1].trim().split(' ');
      // let a = data[i].trim() * 1;
      // const n = data[i] * 1;
      // const p = BigInt(s[0]);
      // const q = BigInt(s[1]);
      // s.sort((a, b) => b - a);
      let obj = {};
      // console.log(p%q)
      // let first = true;
      for (let j = 0; j < s.length; j += 1) {
        if (obj[s[j]]) obj[s[j]] = -1;
        else {
          obj[s[j]] = {};
          obj[s[j]]['count'] = 1;
          obj[s[j]]['index'] = j + 1;
        }
      }
      let idx = -1;
      for (let key in obj) {
        if (obj[key]['count'] > 0) {idx = obj[key]['index']; break;}
      }
      // let j = n;
      console.log(idx);
      i += 2;
    }
}

"use strict";

(() => {

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

    let curLine = 0, allLines = [];

    let nextLine = () => {
        if(curLine == allLines.length) throw new ReferenceError("No more input in the buffer");
        return allLines[curLine++]
    };

    readline.on("line", line => { allLines.push(line); });
    readline.on("close", () => { main(nextLine) });

})();

function main(nextLine) {
    let t = Number(nextLine());

    while(t--) {
        let n = Number(nextLine());
        let ara = nextLine().split(" ").map((x, index) => [Number(x), index+1]);

        ara.sort((a, b) => a[0]-b[0]);

        let mn = -1;
        for(let i = 0; i < n; i++) {
            if((i === 0 || ara[i][0] !== ara[i-1][0]) && (i === n-1 || ara[i][0] !== ara[i+1][0])) {
                mn = ara[i][1];
                break;
            }
        }

        console.log(mn);
    }
}

/* this language fucking sucks */

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

let lines = [];

rl.on('line', (data) => {
    lines.push(data);
    if(lines.length > 0 && 2 * parseInt(lines[0]) === lines.length - 1) {
	rl.close();
	main();
    }
});

async function main() {
    let t = parseInt(lines[0]);
    for(let i = 1; i <= 2 * t; i += 2) {
	let n = parseInt(lines[i]);
	const arr = lines[i + 1].split(' ').map(x => parseInt(x));

	let dict = {};
	for(const v of arr) {
	    if(!dict.hasOwnProperty(v)) {
		dict[v] = 1;
	    }
	    else {
		dict[v]++;
	    }
	}

	let num = -1;
	for(let j = 1; j <= n; j++) {
	    if(dict[j] === 1) {
		num = j;
		break;
	    }
	}

	let ok = false;
	for(let j = 0; j < n; j++) {
	    if(arr[j] === num) {
		console.log(j + 1);
		ok = true;
	    }
	}

	if(!ok) {
	    console.log(-1);
	}
    }
}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;o<t;++o){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const o=n(r(747));let s="",i=[],u=0,l="";const a="local"===process.argv[2],p=t=>{if(a){if(i=o.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),o.default.writeFileSync("output.txt",l),console.log(l),o.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{s+=t})),process.stdin.on("end",(e=>{i=s.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function f(){return i[u++]}function h(){return f().split(" ").map((t=>parseFloat(t)))}function c(){return f().split("")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){a&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const o=n(r(312));o.default.runEachTest((function(){let[t]=o.default.nextNumbers(),e=o.default.nextNumbers(),r={};for(let n=0;n<t;++n){let t=e[n];r[t]={val:null==r[t]?1:r[t].val+1,ndx:n}}e.sortAsc();for(let t of e)if(1==r[t].val)return void o.default.puts(r[t].ndx+1);o.default.puts(-1)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let cnt: any = {}
//
//   for (let i = 0; i < n; ++i) {
//     let x = a[i]
//     cnt[x] = { val: cnt[x] == undefined ? 1 : cnt[x].val + 1, ndx: i }
//   }
//
//   // io.debug(cnt)
//
//   a.sortAsc()
//
//   for (let x of a) {
//     if (cnt[x].val == 1) {
//       io.puts(cnt[x].ndx + 1)
//       return
//     }
//   }
//
//   io.puts(-1)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

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

let inputString = '';
let currentLine = 0;

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

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

    B();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t){
        t--;
        let n = pi(readline());
        let res = '';
        for(let i = 1; i <= n; i++){
            if(i !== n){
                res += ` ${i+1}`;
            }else{
                res += ` ${1}`;
            }
        }

        console.log(res.trim());
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let x = readline().split(' ');
        let a = new Array(n);
        let max = 0;
        for(let i = 0; i < n; i++)
            max = Math.max(max, pi(x[i]));
        let map = new Array(max+2);
        let rMap = new Array(max+2);

        for(let i = 0; i < n; i++){
            a[i] = pi(x[i]);
            if(map[a[i]] !== undefined){
                map[a[i]] += 1;
                rMap[a[i]] = i;
            }else{
                map[a[i]]  = 1;
                rMap[a[i]] = i;
            }
        }

        let min = 99999999999;
        for(let i = 0; i < a.length; i++){
            if(map[a[i]] === 1){
                min = Math.min(min, a[i]);
            }
        }

        console.log(min === 99999999999 ? -1 : rMap[min]+1);
    }
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        let map = new Array(200005);
        //map.fill(0);
        for(let i = 0; i < n; i++){
            if(i === 0){
                map[a[i]] = 1;
                continue;
            }

            if(a[i] !== a[i-1]){
                if(map[a[i]] !== undefined){
                    map[a[i]] += 1;
                }else{
                    map[a[i]]  = 1;
                }
            }
        }

        let min = 99999999;
        for(let i = 0; i < n; i++){
            if(map[a[i]] !== undefined){
                if(a[i] === a[0] && a[i] === a[n-1]){
                    min = Math.min(min, map[a[i]]-1);
                }else if(a[i] === a[0] || a[i] === a[n-1]){
                    min = Math.min(min, map[a[i]]);
                }else{
                    min = Math.min(min, map[a[i]]+1);
                }
            }
        }

        console.log(min === 99999999 ? 0 : min);
    }
}

let getFactors = (n) => {
    let i = 2;
    let res = [];
    while(i*i <= n){
        if(n%i === 0)
            res.push([i,n/i]);
        i++;
    }
    return res;
}

function D(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let dp = new Array(Math.floor(n+1));
        dp.fill(1);

        for(let i = 0; i < dp.length; i++){
            let f = getFactors(i);
            if(f.length !== 0){
                for(let j = 0; j < f.length; j++){
                    if(f[j][1] % f[j][0] === 0)
                        dp[i] = Math.max(dp[i], dp[f[j][0]]+dp[f[j][1]]);
                }
            }
        }

        let f = getFactors(n);
        let max = 1;
        if(f.length > 0){
            for(let i = 0; i < f.length; i++){
                if(f[i][1] % f[i][0] === 0)
                    max = Math.max(max, dp[f[i][0]]+dp[f[i][1]]);
            }
        }
        console.log(max);
    }
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var arr = readline().split(' ').map(i => +i);
  var tmp = {};
  var idx = -1;

  arr.forEach(item => {
    if (tmp[item] === undefined) {
      tmp[item] = 0;
    }
    tmp[item]++;
  });

  for (var k in tmp) {
    if (tmp[k] == 1) {
      idx = arr.indexOf(+k) + 1;
      break;
    }
  }

  print(idx || -1);
}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;o<t;++o){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const o=n(r(747));let i="",s=[],u=0,l="";const a="local"===process.argv[2],p=t=>{if(a){if(s=o.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),o.default.writeFileSync("output.txt",l),console.log(l),o.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{i+=t})),process.stdin.on("end",(e=>{s=i.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function h(){return f().split(" ").map((t=>parseFloat(t)))}function c(){return f().split("")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){a&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const o=n(r(312));o.default.runEachTest((function(){let[t]=o.default.nextNumbers(),e=o.default.nextNumbers(),r={};for(let n=0;n<t;++n){let t=e[n];r[t]={val:null==r[t]?1:r[t].val+1,ndx:n}}e.sort();for(let t of e)if(1==r[t].val)return void o.default.puts(r[t].ndx+1);o.default.puts(-1)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let cnt: any = {}
//
//   for (let i = 0; i < n; ++i) {
//     let x = a[i]
//     cnt[x] = { val: cnt[x] == undefined ? 1 : cnt[x].val + 1, ndx: i }
//   }
//
//   // io.debug(cnt)
//
//   a.sort()
//
//   for (let x of a) {
//     if (cnt[x].val == 1) {
//       io.puts(cnt[x].ndx + 1)
//       return
//     }
//   }
//
//   io.puts(-1)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var arr = readline().split(' ').map(i => +i);
  var tmp = {};
  var idx;

  arr.forEach(item => {
    if (tmp[item] === undefined) {
      tmp[item] = 0;
    }
    tmp[item]++;
  });

  for (var k in tmp) {
    idx = arr.indexOf(tmp[k]) + 1;
    break;
  }

  print(idx || -1);
}


The only difference between easy and hard versions are constraints on $$$n$$$ and $$$k$$$.You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most $$$k$$$ most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals $$$0$$$).Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.You (suddenly!) have the ability to see the future. You know that during the day you will receive $$$n$$$ messages, the $$$i$$$-th message will be received from the friend with ID $$$id_i$$$ ($$$1 \le id_i \le 10^9$$$).If you receive a message from $$$id_i$$$ in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.Otherwise (i.e. if there is no conversation with $$$id_i$$$ on the screen):  Firstly, if the number of conversations displayed on the screen is $$$k$$$, the last conversation (which has the position $$$k$$$) is removed from the screen.  Now the number of conversations on the screen is guaranteed to be less than $$$k$$$ and the conversation with the friend $$$id_i$$$ is not displayed on the screen.  The conversation with the friend $$$id_i$$$ appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down. Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all $$$n$$$ messages.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 200)$$$ — the number of messages and the number of conversations your smartphone can show. The second line of the input contains $$$n$$$ integers $$$id_1, id_2, \dots, id_n$$$ ($$$1 \le id_i \le 10^9$$$), where $$$id_i$$$ is the ID of the friend which sends you the $$$i$$$-th message.

In the first line of the output print one integer $$$m$$$ ($$$1 \le m \le min(n, k)$$$) — the number of conversations shown after receiving all $$$n$$$ messages. In the second line print $$$m$$$ integers $$$ids_1, ids_2, \dots, ids_m$$$, where $$$ids_i$$$ should be equal to the ID of the friend corresponding to the conversation displayed on the position $$$i$$$ after receiving all $$$n$$$ messages.

NoteIn the first example the list of conversations will change in the following way (in order from the first to last message):  $$$[]$$$;  $$$[1]$$$;  $$$[2, 1]$$$;  $$$[3, 2]$$$;  $$$[3, 2]$$$;  $$$[1, 3]$$$;  $$$[1, 3]$$$;  $$$[2, 1]$$$. In the second example the list of conversations will change in the following way:  $$$[]$$$;  $$$[2]$$$;  $$$[3, 2]$$$;  $$$[3, 2]$$$;  $$$[1, 3, 2]$$$;  and then the list will not change till the end.

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

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

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const l1 = arr.shift().split(' ')
  const n = parseInt(l1[0])
  const k = parseInt(l1[1])
  const messages = arr.shift().split(' ')
  messages[messages.length - 1] = parseInt(messages[messages.length - 1])

  let map = {}
  let current = 0, left = 1, right = 0
  let reverseMap = {}

  for(let i = 0; i < n; i++) {
    const m = messages[i]
    if(!map[m]){
      if(current == k){
        delete map[reverseMap[left]]
        reverseMap[left ++] = null
      }
      else{
        current ++
      }
      map[m] = ++ right
      reverseMap[right] = m
      // console.log(m, map, reverseMap, left, right, current)
    }
  }
  // if(k == 3) console.log(map, reverseMap)

  console.log(current)

  for(let i = right; i >= left; i --){
    process.stdout.write(reverseMap[i] + ' ')
  }
  console.log()

})

'use strict'

const k = parseInt(readline().split(' ')[1]);
const d = {};
let r = [];

readline().split(' ').forEach((i) => {
    if (d[i]) return;
    if (r.length >= k) d[r[r.length - k]] = undefined;
    r.push(i);
    d[i] = true;
});
r = r.slice(-k);
write(r.length + '\n' + r.reverse().join(' '));

var stats = readline().split(' ').map(function (num) {
  return parseInt(num);
})

var messages = readline().split(' ').map(function (num) {
  return parseInt(num);
})
// var stats = [1, 2];
// var messages = [1, 2, 3, 2, 1, 3, 2];

var currIds = [];
var dict = {}

for (var i = 0; i < messages.length; i++) {
  if (dict[(messages[i]) + ''])
    continue;
  else if (currIds.length === stats[1]) {
    var toPop = currIds[0];
    dict[toPop + ''] = undefined;
    dict[messages[i]] = 'exist';
    currIds.push(messages[i]);
    currIds.shift();
  } else {
    dict[messages[i]] = 'exist';
    currIds.push(messages[i]);
  }
}

currIds.reverse();
write(currIds.length + '\n')
write(currIds.join(' '))

'use strict'

const k = parseInt(readline().split(' ')[1]);

const res = readline().split(' ').reduce((r, i) => {
    if (r.indexOf(i) === -1) {
        if (r.length === k) r.pop();
        r.unshift(i);
    }
    return r;
}, []);

write(res.length + '\n' + res.join(' '));

var stats = readline().split(' ').map(function (num) {
  return parseInt(num);
})

var messages = readline().split(' ').map(function (num) {
  return parseInt(num);
})
// var stats = [1, 2];
// var messages = [1, 2, 3, 2, 1, 3, 2];

var currIds = [];

for (var i = 0; i < messages.length; i++) {
  if (currIds.includes(messages[i]))
    continue;
  else if (currIds.length === stats[1]) {
    currIds.push(messages[i]);
    currIds.shift()
  } else {
    currIds.push(messages[i]);
  }
}

currIds.reverse();
write(currIds.length + '\n')
write(currIds.join(' '))

var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
var STATE = 1;
var n, k, params, ids, item;
rl.on('line', function (input) {
  switch (STATE) {
    case 1:
      params = input.split(' ');
      n = parseInt(params[0], 10);
      k = parseInt(params[1], 10);
      STATE = 2;
      break;
    case 2:
      params = input.split(' ');
      ids = new Array()
      for (var i = 0; i < n; i++) {
        item = params[i];
        if (!ids.includes(item)) {
          ids.push(item)
        }
        if (ids.length > k) {
          ids.shift()
        }
      }
      console.log(ids.length);
      console.log(ids.reverse().join(' '));
      STATE = 1;
      break;
    default:
      // code
  }
}).on('close', function() {
  process.exit(0);
});

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

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

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const l1 = arr.shift().split(' ')
  const n = parseInt(l1[0])
  const k = parseInt(l1[1])
  const messages = arr.shift().split(' ')
  messages[messages.length - 1] = parseInt(messages[messages.length - 1])

  let map = {}
  let current = 0
  let q = []

  for(let i = 0; i < n; i++) {
    const m = messages[i]
    if(!map[m]){
      q.unshift(m)
      if(current == k) map[q.pop()] = false
      else{
        current ++
      }
      map[m] = true
    }
  }
  // if(k == 4) console.log(map, q)

  console.log(q.length)
  for(let i = 0, len = q.length; i < len; i++) {
    process.stdout.write(q[i] + ' ')
  }
  console.log()

})

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL);

    function foo (data, k) {
        let result = data.reduce((acc, value) => {
            if (~acc.indexOf(value)) return acc;
            else if (acc.length < k) {
                acc.unshift(value)
            } else {
                acc.pop();
                acc.unshift(value);
            }
            return acc;
        }, [])

        return result;

    }

    let k = lines[0].split(" ").map(Number)[1];
    let data = lines[1].split(" ").map(Number);

    let result = foo(data, k);
    let answer = '';
    answer += result.length + "\n";
    answer += result.join(" ")
    console.log(answer);
})

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const firstLine = readline().split(" ");
    const n = parseInt(firstLine[0]);
    const k = parseInt(firstLine[1]);
    const ids = readline().split(" ").map((value,index,array)=>{return parseInt(value)});

    let screen = [];
    for(let i = 0;i<n;i++){
        if(screen.indexOf(ids[i]) != -1){
            continue;
        }
        if(screen.length == k){
            screen.pop();
        }
        screen.unshift(ids[i]);
    }
    console.log(screen.length);
    let output = "";
    screen.forEach((element)=>{output += element +" ";});
    console.log(output);
}

'use strict'

const k = parseInt(readline().split(' ')[1]);

const res = readline().split(' ').reduce((r, i) => {
    if (r.slice(-k).indexOf(i) === -1) r.push(i);
    return r;
}, []).slice(-k);

write(res.length + '\n' + res.join(' '));

'use strict'

const k = parseInt(readline().split(' ')[1]);

const res = readline().split(' ').reduce((r, i) => {
    if (r.indexOf(i) === -1) {
        if (r.length === k) r.pop();
        r.unshift(i);
    }
    return r;
}, []);

write(res.length + '\n' + res.reverse().join(' '));

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

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

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const l1 = arr.shift().split(' ')
  const n = parseInt(l1[0])
  const k = parseInt(l1[1])
  const messages = arr[0].split(' ')

  let map = {}
  let current = 0
  let q = []

  for(let i = 0; i < n; i++) {
    const m = messages[i]
    if(!map[m]){
      q.unshift(m)
      if(current == k) map[q.pop()] = false
      else{
        current ++
      }
      // console.log(map, q)
      map[m] = true
    }
  }

  console.log(q.length)
  for(let i = 0, len = q.length; i < len; i++) {
    process.stdout.write(q[i] + ' ')
  }
  console.log()

})

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

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

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const l1 = arr.shift().split(' ')
  const n = parseInt(l1[0])
  const k = parseInt(l1[1])
  const messages = arr[0].split(' ')

  let map = {}
  let current = 0
  let q = []

  for(let i = 0; i < n; i++) {
    const m = messages[i]
    if(!map[m]){
      q.unshift(m)
      if(current == k) map[q.pop()] = false
      else{
        current ++
      }
      // console.log(map, q)
      map[m] = true
    }
  }

  for(let i = 0, len = q.length; i < len; i++) {
    process.stdout.write(q[i] + ' ')
  }
  console.log()

})

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

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

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const l1 = arr.shift().split(' ')
  const n = parseInt(l1[0])
  const k = parseInt(l1[1])
  const messages = arr.shift().split(' ')

  let map = {}
  let current = 0
  let q = []

  for(let i = 0; i < n; i++) {
    const m = messages[i]
    if(!map[m]){
      q.unshift(m)
      if(current == k) map[q.pop()] = false
      else{
        current ++
      }
      map[m] = true
    }
  }
  if(k == 4) console.log(map, q)

  console.log(q.length)
  for(let i = 0, len = q.length; i < len; i++) {
    process.stdout.write(q[i] + ' ')
  }
  console.log()

})

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

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

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const l1 = arr.shift().split(' ')
  const n = parseInt(l1[0])
  const k = parseInt(l1[1])
  const messages = arr[0].split(' ')

  let map = {}
  let current = 0
  let q = []

  for(let i = 0; i < n; i++) {
    const m = messages[i]
    if(!map[m]){
      q.unshift(m)
      if(current == k) map[q.pop()] = false
      else{
        current ++
      }
      map[m] = true
    }
  }
  if(k == 4) console.log(map, q)

  console.log(q.length)
  for(let i = 0, len = q.length; i < len; i++) {
    process.stdout.write(q[i] + ' ')
  }
  console.log()

})

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL);

    function foo (data, k) {
        let result = data.reduce((acc, value) => {
            if (~acc.indexOf(value)) return acc;
            else if (acc.length < k) {
                acc.unshift(value)
            } else {
                acc.pop();
                acc.unshift(value);
            }
            return acc;
        }, []);
        return result;
    }

    let k = lines[0].split(" ").map(Number)[1];
    let data = lines[1].split(" ").map(Number);

    let result = foo(data, k);
    console.log(result);
})

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL);

    function foo (data, k) {
        let result = data.reduce((acc, value) => {
            if (~acc.indexOf(value)) return acc;
            else if (acc.length < k) {
                acc.unshift(value)
            } else {
                acc.pop();
                acc.unshift(value);
            }
            return acc;
        }, [])

        return result.join(" ");

    }

    let k = lines[0].split(" ").map(Number)[1];
    let data = lines[1].split(" ").map(Number);

    let result = foo(data, k);
    console.log(result);
})


There are $$$n$$$ rectangles in a row. You can either turn each rectangle by $$$90$$$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such).

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of rectangles. Each of the next $$$n$$$ lines contains two integers $$$w_i$$$ and $$$h_i$$$ ($$$1 \leq w_i, h_i \leq 10^9$$$) — the width and the height of the $$$i$$$-th rectangle.

Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO". You can print each letter in any case (upper or lower).

NoteIn the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].In the second test, there is no way the second rectangle will be not higher than the first one.

function main() {
  const is = new Scanner();
  const n = is.nextLine();
  const rectangles = new Array(n);
  for (let i = 0; i < n; i += 1) {
    rectangles[i] = is.nextArray().map(Number);
  }

  const sequence = [Math.max(rectangles[0][0], rectangles[0][1])];
  let answer = true;
  for (let i = 1; i < n; i += 1) {

    if (rectangles[i][0] > rectangles[i][1]) {
      if (rectangles[i][0] > sequence[i - 1])
        sequence.push(rectangles[i][1]);
      else
        sequence.push(rectangles[i][0]);
    } else {
      if (rectangles[i][1] > sequence[i - 1])
        sequence.push(rectangles[i][0]);
      else
        sequence.push(rectangles[i][1]);
    }

    if (sequence[i] > sequence[i - 1])
      answer = false;
  }

  console.log(answer ? 'YES' : 'NO');

}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

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

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

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

  nextArray() {
    return this.nextLine().split(' ');
  }

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

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

var n = readline();

var arr = [];

for( var i=1; i<=n; i++ ) {
    arr.push(readline().split(' ').map(Number))
}

var prev = Math.min( arr[n-1][0], arr[n-1][1]);

var flg = true;

for( var i=n-2; i>=0; i-- ) {
    //print(arr[i][0]+ " " + arr[i][1]);
    var mn1 = Math.min( arr[i][0], arr[i][1] );
    var mn2;

    if( mn1 == arr[i][0] ) mn2 = arr[i][1];
    else mn2 = arr[i][0];

    if( prev <= mn1 ) {
        prev = mn1;
    } else if( prev <= mn2 ) {
        prev = mn2;
    } else {
        flg = false;
    }

}

if( flg ) {
    print('YES');
} else {
    print('NO');
}


You are given a permutation $$$a$$$ of size $$$n$$$ and you should perform $$$n$$$ operations on it. In the $$$i$$$-th operation, you can choose a non-empty suffix of $$$a$$$ and increase all of its elements by $$$i$$$. How can we perform the operations to minimize the number of inversions in the final array?Note that you can perform operations on the same suffix any number of times you want.A permutation of size $$$n$$$ is an array of size $$$n$$$ such that each integer from $$$1$$$ to $$$n$$$ occurs exactly once in this array. A suffix is several consecutive elements of an array that include the last element of the array. An inversion in an array $$$a$$$ is a pair of indices $$$(i, j)$$$ such that $$$i > j$$$ and $$$a_{i} < a_{j}$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of the array. The second line contains $$$n$$$ distinct integers $$$a_{1}, a_{2}, \dots, a_{n}$$$ ($$$1 \le a_i \le n$$$), the initial permutation $$$a$$$. It's guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print $$$n$$$ integers $$$x_{1}, x_{2}, \ldots, x_{n}$$$ ($$$1 \le x_{i} \le n$$$ for each $$$1 \le i \le n$$$) indicating that the $$$i$$$-th operation must be applied to the suffix starting at index $$$x_{i}$$$. If there are multiple answers, print any of them.

NoteIn the first test case one of the optimal solutions is to increase the whole array on each operation (that is, choose the suffix starting at index $$$1$$$). The final array $$$[11, 12, 13, 14]$$$ contains $$$0$$$ inversions.In the second test case, $$$a$$$ will be equal to $$$[2, 4, 3, 5, 6]$$$, $$$[2, 4, 3, 7, 8]$$$, $$$[2, 4, 6, 10, 11]$$$, $$$[2, 8, 10, 14, 15]$$$ and $$$[7, 13, 15, 19, 20]$$$ after the first, second, third, fourth, and fifth operations, respectively. So the final array $$$a$$$ has zero inversions.

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

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

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    for (let i = 0; i < n; i++) arr[i] = [arr[i], i + 1];
    arr.sort((a, b) => a[0] - b[0]);
    let ans = new Array(n).fill(0);
    for (let i = 0; i < n; i++) {
      ans[n - i - 1] = arr[i][1];
    }
    console.log(ans.join(" "));
  }
};
solve();

'use strict';

var fs = require('fs');

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

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

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = rns();
  const queue = new Heap((a, b) => a[1] !== b[1] ? b[1] - a[1] : b[0] - a[0]);
  for (let i = n - 1; i > 0; i--) {
    if (a[i] < a[i - 1]) queue.push([i + 1, a[i - 1] - a[i]]);
  }
  const res = [];
  for (let i = n - 1; i >= 0; i--) {
    if (queue.size()) {
      const cur = queue.pop();
      res[i] = cur[0];
      if (cur[1] > i + 1) {
        cur[1] -= i + 1;
        queue.push(cur);
      }
    } else {
      res[i] = 1;
    }
  }
  return res.join(' ');
}
class Heap {
  constructor(_comparator = (a, b) => a - b, arr) {
    _defineProperty(this, "_heap", []);
    this._comparator = _comparator;
    if (arr) {
      this._heap = [...arr];
      for (let i = arr.length >> 1; i; i--) this.down(i);
    }
  }
  swap(i, j) {
    [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
  }
  _has(i) {
    return Object.prototype.hasOwnProperty.call(this._heap, i);
  }
  comparator(i, j) {
    return this._comparator(this._heap[i], this._heap[j]) < 0;
  }
  parent(i) {
    return i - 1 >> 1;
  }
  children(i) {
    return [2 * i + 1, 2 * i + 2];
  }
  up(i) {
    let parent = this.parent(i);
    while (i > 0 && this.comparator(i, parent)) {
      this.swap(i, parent);
      [i, parent] = [parent, parent - 1 >> 1];
    }
  }
  down(i) {
    let [left, right] = this.children(i);
    while (left < this._heap.length) {
      if (!this._has(right)) right = left;
      if (this.comparator(right, left)) [left, right] = [right, left];
      if (this.comparator(i, left)) break;
      this.swap(i, left);
      i = left;
      [left, right] = [2 * i + 1, 2 * i + 2];
    }
  }
  push(node) {
    this._heap.push(node);
    this.up(this._heap.length - 1);
  }
  pop() {
    if (this.size() === 0) return null;
    let res = this._heap[0];
    this.swap(0, this._heap.length - 1);
    this._heap.pop();
    this.down(0);
    return res;
  }
  remove(i) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this.swap(i, this._heap.length - 1);
    this._heap.pop();
    this.down(i);
    this.up(i);
    return res;
  }
  modify(i, val) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this._heap[i] = val;
    this.down(i);
    this.up(i);
    return res;
  }
  top() {
    if (this.size() === 0) return null;
    return this._heap[0];
  }
  size() {
    return this._heap.length;
  }
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

function solve() {
    var n = Number(read());
    var a = readArray(Number);
    var ans = [];
    var nextFree = [];
    for (var i = 1; i < n; i++) {
        if (a[i] > a[i - 1]) {
            continue;
        }
        var diff = a[i - 1] - a[i];
        var start = diff;
        while(ans[diff]) {
            diff = nextFree[diff] || (diff + 1);
        }
        nextFree[start] = diff + 1;
        ans[diff] = i + 1;
    }
    for (i = 0; i < n; i++) {
        ans[i] = ans[i + 1] || 1;
    }
    write(ans.slice(0, n).join(' '));
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

var MEMORY;
var MEMORY_INDEX = 0;
var ANS = '';

try {
    initInput(start);
} catch (e) {
    console.log(e);
}
function readArray(f) {
    return read().split(' ').map(f);
}

function sortNumbers(a, b) {
    return a - b;
}
function sortNumbersDec(a, b) {
    return b - a;
}
var ANS;
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}

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

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

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let ans = new Array(n).fill(1);
    let maxArr = [];
    maxArr.push(arr[0]);
    for (let i = 1; i < n; i++)
      maxArr.push(Math.max(maxArr[maxArr.length - 1], arr[i]));
    for (let i = n - 2; i >= 0; i--) {
      if (maxArr[i] > arr[i + 1]) {
        ans[maxArr[i] - arr[i + 1]] = i + 2;
      }
    }
    console.log(ans.join(" "));
  }
};
solve();

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

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

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let ans = new Array(n).fill(1);
    let maxArr = [];
    maxArr.push(arr[0]);
    for (let i = 1; i < n; i++)
      maxArr.push(Math.max(maxArr[maxArr.length - 1], arr[i]));
    for (let i = n - 2; i >= 0; i--) {
      if (arr[i] > arr[i + 1]) {
        ans[maxArr[i] - arr[i + 1]] = i + 2;
      }
    }
    console.log(ans.join(" "));
  }
};
solve();

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

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

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let ans = new Array(n).fill(1);
    for (let i = n - 2; i >= 0; i--) {
      if (arr[i] > arr[i + 1]) {
        ans[arr[i] - arr[i + 1]] = i + 2;
      }
    }
    console.log(ans.join(" "));
  }
};
solve();

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = rns();
  let res = [];
  for (let i = n - 1; i > 0; i--) {
    if (a[i] < a[i - 1]) {
      for (let j = 0; j < a[i - 1] - a[i] && res.length < n; j++) {
        res.push(i + 1);
      }
    }
  }
  for (let i = res.length; i < n; i++) res[i] = 1;
  return res.join(' ');
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = rns();
  let res = [];
  for (let i = n - 1; i > 0; i--) {
    if (a[i] < a[i - 1]) res.push([i + 1, a[i - 1] - a[i]]);
  }
  res.sort((a, b) => b[1] - a[1]);
  const ans = [];
  for (let i = 0; i < n; i++) {
    while (res.length && res[res.length - 1][1] === 0) res.pop();
    if (res.length) {
      ans[i] = res[res.length - 1][0];
      res[res.length - 1][1]--;
    } else {
      ans[i] = 1;
    }
  }
  return ans.join(' ');
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = rns();
  let res = [1];
  for (let i = n - 1; i > 0; i--) {
    if (a[i] < a[i - 1]) {
      for (let j = 0; j < a[i - 1] - a[i]; j++) {
        res.push(i + 1);
      }
    }
  }
  return res.join(' ');
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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


A super computer has been built in the Turtle Academy of Sciences. The computer consists of n·m·k CPUs. The architecture was the paralellepiped of size n × m × k, split into 1 × 1 × 1 cells, each cell contains exactly one CPU. Thus, each CPU can be simultaneously identified as a group of three numbers from the layer number from 1 to n, the line number from 1 to m and the column number from 1 to k.In the process of the Super Computer's work the CPUs can send each other messages by the famous turtle scheme: CPU (x, y, z) can send messages to CPUs (x + 1, y, z), (x, y + 1, z) and (x, y, z + 1) (of course, if they exist), there is no feedback, that is, CPUs (x + 1, y, z), (x, y + 1, z) and (x, y, z + 1) cannot send messages to CPU (x, y, z).Over time some CPUs broke down and stopped working. Such CPUs cannot send messages, receive messages or serve as intermediates in transmitting messages. We will say that CPU (a, b, c) controls CPU (d, e, f) , if there is a chain of CPUs (xi, yi, zi), such that (x1 = a, y1 = b, z1 = c), (xp = d, yp = e, zp = f) (here and below p is the length of the chain) and the CPU in the chain with number i (i < p) can send messages to CPU i + 1.Turtles are quite concerned about the denial-proofness of the system of communication between the remaining CPUs. For that they want to know the number of critical CPUs. A CPU (x, y, z) is critical, if turning it off will disrupt some control, that is, if there are two distinctive from (x, y, z) CPUs: (a, b, c) and (d, e, f), such that (a, b, c) controls (d, e, f) before (x, y, z) is turned off and stopped controlling it after the turning off.

The first line contains three integers n, m and k (1 ≤ n, m, k ≤ 100) — the dimensions of the Super Computer.  Then n blocks follow, describing the current state of the processes. The blocks correspond to the layers of the Super Computer in the order from 1 to n. Each block consists of m lines, k characters in each — the description of a layer in the format of an m × k table. Thus, the state of the CPU (x, y, z) is corresponded to the z-th character of the y-th line of the block number x. Character "1" corresponds to a working CPU and character "0" corresponds to a malfunctioning one. The blocks are separated by exactly one empty line.

Print a single integer — the number of critical CPUs, that is, such that turning only this CPU off will disrupt some control.

NoteIn the first sample the whole first layer of CPUs is malfunctional. In the second layer when CPU (2, 1, 2) turns off, it disrupts the control by CPU (2, 1, 3) over CPU (2, 1, 1), and when CPU (2, 2, 2) is turned off, it disrupts the control over CPU (2, 2, 3) by CPU (2, 2, 1).In the second sample all processors except for the corner ones are critical.In the third sample there is not a single processor controlling another processor, so the answer is 0.

dimension = readline().split(' '),
	n = dimension[0],
	m = dimension[1],
	k = dimension[2];

var prev,
	curr,
	next;

var counter = 0;
for (i = 0; i < n; i++) {
	if (!curr) {
		curr = readBlock();
		readline();
	}
	if (i != n - 1) {
		next = readBlock();
		if (i != n - 2) {
			readline();
		}
	}

	for (l = 0; l < m; l++) {
		for (p = 0; p < k; p++) {
			var flag = false;
				if (curr[l][p]) {
				if (curr[l][p - 1]) {
					if (curr[l][p + 1]) {
						flag = true;
					}
					if (curr[l + 1]) {
						if (curr[l + 1][p] && !curr[l + 1][p - 1]) {
							flag = true;
						}
					}
					if (i < n - 1) {
						if (next[l][p] && !next[l][p - 1]) {
							flag = true;
						}
					}
				}

				if (curr[l - 1]) {
					if (curr[l - 1][p]) {
						if (curr[l + 1]) {
							if (curr[l + 1][p]) {
								flag = true;
							}
						}
						if (curr[l][p + 1] && !curr[l - 1][p + 1]) {
							flag = true;
						}
						if (i < n - 1) {
							if (next[l][p] && !next[l - 1][p]) {
								flag = true;
							}
						}
					}
				}

				if (prev) {
					if (prev[l][p]) {
						if (i < n - 1) {
							if (next[l][p]) {
								flag = true;
							}
						}
						if (curr[l][p + 1] && !prev[l][p + 1]) {
							flag = true;
						}
						if (curr[l + 1]) {
							if (curr[l + 1][p] && !prev[l + 1][p]) {
								flag = true;
							}
						}
					}
				}

				if (flag)  {
					counter++;
				}

			}
		}
	}
	prev = curr;
	curr = next;
}

print(counter);

function readBlock() {
	var block = [];
	for (j = 0; j < m; j++) {
		block.push(readline().split('').map((v) => {
			return Number(v);
		}));
	}
	return block;
}

var dimension = readline().split(' '),
	n = dimension[0],
	m = dimension[1],
	k = dimension[2];

var prev,
	curr,
	next;

var counter = 0;
for (i = 0; i < n; i++) {
	if (!curr) {
		curr = readBlock();
		readline();
	}
	if (i != n - 1) {
		next = readBlock();
		if (i != n - 2) {
			readline();
		}
	}
	if (i == n - 1) {
		delete next;
	}
	for (l = 0; l < m; l++) {
		for (p = 0; p < k; p++) {
			if (curr[l][p]) {
				var flag = false;
				if (curr[l][p + 1] && curr[l][p - 1]) {
					flag = true;
				}
				if (curr[l - 1] && curr[l + 1]) {
					if (curr[l - 1][p] && curr[l + 1][p]) {
						flag = true;
					}
				}
				if (i != 0 && i != n - 1) {
					if (prev[l][p] && next[l][p]) {
						flag = true;
					}
				}

				if (flag) {
					counter++;
				}
			}
		}
	}
	prev = curr;
	curr = next;
}

print(counter);

function readBlock() {
	var block = [];
	for (j = 0; j < m; j++) {
		block.push(readline().split('').map((v) => {
			return Number(v);
		}));
	}
	return block;
}

dimension = readline().split(' '),
	n = dimension[0],
	m = dimension[1],
	k = dimension[2];

var prev,
	curr,
	next;

var counter = 0;
for (i = 0; i < n; i++) {
	if (!curr) {
		curr = readBlock();
		readline();
	}
	if (i != n - 1) {
		next = readBlock();
		if (i != n - 2) {
			readline();
		}
	}

	for (l = 0; l < m; l++) {
		for (p = 0; p < k; p++) {
			var flag = false;
			var f = 0;
			var s = 0;
			var t = 0;
			if (curr[l][p]) {
				if (curr[l][p - 1]) {
					if (curr[l][p + 1]) {
						flag = true;
					}
					if (curr[l + 1]) {
						if (curr[l + 1][p] && !curr[l + 1][p - 1]) {
							flag = true;
						}
					}
					if (i < n - 1) {
						if (next[l][p] && !next[l][p - 1]) {
							flag = true;
						}
					}
				}
				if (flag) {
					f++;
				}

				if (curr[l - 1]) {
					if (curr[l - 1][p]) {
						if (curr[l + 1]) {
							if (curr[l + 1][p]) {
								flag = true;
							}
						}
						if (curr[l][p + 1] && !curr[l - 1][p + 1]) {
							flag = true;
						}
						if (i < n - 1) {
							if (next[l][p] && !next[l - 1][p]) {
								flag = true;
							}
						}
					}
				}
				if (flag && !f) {
					s++;
				}

				if (prev) {
					if (prev[l][p]) {
						if (i < n - 1) {
							if (next[l][p]) {
								flag = true;
							}
						}
						if (curr[l][p + 1] && !prev[l][p + 1]) {
							flag = true;
						}
						if (curr[l + 1]) {
							if (curr[l + 1][p] && !prev[l + 1][p]) {
								flag = true;
							}
						}
					}
				}
				if (flag && !f & !s) {
					t++
				}

				if (flag)  {
					counter++;
				}

			}
			print(f, s, t)
		}
	}
	prev = curr;
	curr = next;
}

print(counter);

function readBlock() {
	var block = [];
	for (j = 0; j < m; j++) {
		block.push(readline().split('').map((v) => {
			return Number(v);
		}));
	}
	return block;
}