var n=Number(readline())
var P=readline().split(' ').map(Number)
var C=readline().split(' ').map(Number)
var T=new Array(n)
for (var i=0; i<n; ++i) T[i]={}

for (var i=0; i<P.length; ++i) {
	var q = P[i]-1, w = i + 1;
	T[q][w] = 1;
	T[w][q] = 1;
}

var R=1

function walk(v, p) {
	// print(v, p, C[v], C[p])
	if (p >= 0 && C[v] !== C[p]) ++R;

	for (var k in T[v]) {
		if (k != p) {
			walk(k, v)
		}
	}
}

walk(0, -1)
print(R)

// print(JSON.stringify(T))

var n = Number(readline());
var tree = [];
var arr = readline().split(' ').map(Number);
for (var i = 0; i < n - 1; i++) {
	if (!tree[arr[i] - 1]) {
		tree[arr[i] - 1] = [];
	}
	tree[arr[i] - 1].push(i+1);
}
var color = readline().split(' ').map(Number);

var result = 0;
var curColor = 0;

//print(JSON.stringify(tree));

function order(i, curColor) {
	if (color[i] !== curColor) {
		result += 1;
		curColor = color[i];
	}
	if (tree[i]) {
		for (var j = 0; j < tree[i].length; j++) {
			var child = tree[i][j];
			order(child, curColor);
		}
	}
}

order(0, 0);
print(result);

function main(){
    function solution(n, p, c){
        var graph = [];
        var rootNode = 1;
        var visited = new Set();
        var currentNode = 1;
        var queue = [];
        var currentColors = []; // [0, 0, 0, ..., 0]
        var endingColors = [];
        var steps = 0;
        var colorToPaint = "";

        // var graph = [
        // 	[],
        // 	[2, 5],
        // 	[4, 3],
        // 	[],
        // 	[],
        // 	[6],
        // 	[]
        // ];

        function colorGraph(someNode, someColor){
            if(visited.has(someNode)){
                return;
            }

            currentColors[someNode] = someColor;
            visited.add(someNode);

            var childNodes = graph[someNode];

            if(!childNodes){
                return;
            }

            for(var i = 0; i < childNodes.length; i++){
                var childNode = childNodes[i];
                colorGraph(childNode, someColor);
            }
        }

        var stack = [];

        function colorGraphUsingStack(someNode, someColor){
            stack.push(someNode);

            while(stack.length > 0){
                var current = stack.pop();
                currentColors[current] = someColor;
                var childNodes = graph[current];

                for(var i = 0; i < childNodes.length; i++){
                    var child = childNodes[i];
                    stack.push(child);
                }

            }
        }

        var queueOffset = 0;
        queue.top = function(){
            var top = queue[queueOffset];
            queueOffset++;
            return top;
            //return queue.shift();
        };

        // This operation is O(n), where n is the number of verticies
        function colorsMatch(currentColors, endingColors){
            for(var i = 0; i < endingColors.length; i++){
                if(currentColors[i] !== endingColors[i]){
                    return false;
                }
            }
            return true;
        }

        function bfs(someNode){
            if(colorsMatch(currentColors, endingColors)){
                queue = [];
                return;
            }

            // process current node
            colorToPaint = endingColors[someNode];

            if(currentColors[someNode] !== endingColors[someNode]){
                steps++;
                colorGraphUsingStack(someNode, colorToPaint);
                visited = new Set();
            }

            // get next nodes to process
            var childNodes = graph[someNode];

            if(!childNodes){
                return;
            }

            for(var i = 0; i < childNodes.length; i++){
                var childNode = childNodes[i];
                queue.push(childNode);
            }

            while(queue.length > 0){
                var nextNode = queue.top();
                bfs(nextNode);
            }
        }

        /* A bunch of code needed just to map input into adjacency list */
        /**
         * @Tigran
         * There has to be a better way of creating an adjacency list from the input.
         *
         * Perhaps I shouldn't be using an adjacency list data structure or I am
         * over complicating this in some way.
         *
         */
        function getAdjacencyListFromInput(n, p){

            /**
             * Creates [[], ..., []] of size n
             * @param n
             * @returns {Array}
             */
            function createEmptyAdjacencyList(n){
                var adjancencyList = [];
                for(var i = 0; i < n; i++){
                    adjancencyList.push([]);
                }

                return adjancencyList;
            }

            /**
             * Creates array [2, 3, ..., n+1]
             * @param n
             * @returns {Array}
             */

            function createI(n){
                var i = [];
                for(var k = 0; k < n; k++){
                    i.push(k + 2);
                }
                return i;
            }

            debugger;

            var c = createEmptyAdjacencyList(n + 1); // [[], ..., []] of size n + 1 (where 0 index isn't used)
            var i = createI(n + 1); // [2, 3, ... n+1]

            for(var k = 0; k < n - 1; k++){
                var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]
                var i_k = i[k]; // e.g. [2, 3, 4, 5, 6]
                c[p_k].push(i_k);
            }

            /**
             *  Above could also be this, but makes it harder to read
             *  */
            // for(var k = 0; k < n-1; k++){
            //     var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]
            //     c[p_k].push(k+2);
            // }

            return c; // e.g. [[], [2, 5], [3, 4], [], [], [6]]
        }

        // currentColors = [0, 0, ..., 0] for size N
        function initializeCurrentColors(n){
            // can't use currentColors var name due to compilation issues in codeforces
            var someColors = new Array(n);
            for(var i=0; i < someColors.length; i++){
                someColors[i] = 0;
            }
            return someColors;
        }

        function addZeroToFrontOfArray(someArray){
            someArray.unshift(0);
        }

        graph = getAdjacencyListFromInput(n, p);
        currentColors = initializeCurrentColors(n+1);
        addZeroToFrontOfArray(c);
        endingColors = c;

        bfs(rootNode);
        ans = steps;
    }

    var ans = 0;

    const n = parseInt(readline());
    const p = readline().split(" ").map(Number);
    const c = readline().split(" ").map(Number);

    solution(n, p, c);
    print(ans);
}

main();

function main(){
    function solution(n, p, c){
        var graph = [];
        var rootNode = 1;
        var dfs_visited = new Set();
        var currentNode = 1;
        var queue = [];
        var currentColors = []; // [0, 0, 0, ..., 0]
        var endingColors = [];
        var steps = 0;
        var colorToPaint = "";

        // var graph = [
        // 	[],
        // 	[2, 5],
        // 	[4, 3],
        // 	[],
        // 	[],
        // 	[6],
        // 	[]
        // ];

        /**
         * This is just a dfs for some starting node, to change colors
         * @param someNode
         * @param someColor
         */
        function colorGraph(someNode, someColor){
            if(dfs_visited.has(someNode)){
                return;
            }

            currentColors[someNode] = someColor;
            dfs_visited.add(someNode);

            var childNodes = graph[someNode];

            if(!childNodes){
                return;
            }

            for(var i = 0; i < childNodes.length; i++){
                var childNode = childNodes[i];
                colorGraph(childNode, someColor);
            }
        }

        var stack = [];

        function colorGraphUsingStack(someNode, someColor){
            stack.push(someNode);

            while(stack.length > 0){
                var current = stack.pop();
                currentColors[current] = someColor;
                var childNodes = graph[current];

                if(childNodes == undefined){
                    return;
                }

                for(var i = 0; i < childNodes.length; i++){
                    var child = childNodes[i];
                    stack.push(child);
                }

            }
        }

        var queueOffset = 0;
        queue.top = function(){
            var top = queue[queueOffset];
            queueOffset++;
            return top;
            //return queue.shift();
        };

        // This operation is O(n), where n is the number of vertices
        function colorsMatch(currentColors, endingColors){
            for(var i = 0; i < endingColors.length; i++){
                if(currentColors[i] !== endingColors[i]){
                    return false;
                }
            }
            return true;
        }

        function bfs(someNode){
            // O(n)
            if(colorsMatch(currentColors, endingColors)){
                queue = [];
                return;
            }

            // process current node
            colorToPaint = endingColors[someNode];

            if(currentColors[someNode] !== endingColors[someNode]){
                steps++;
                colorGraphUsingStack(someNode, colorToPaint);
                dfs_visited = new Set();
            }

            // get next nodes to process
            var childNodes = graph[someNode];

            if(!childNodes){
                return;
            }

            for(var i = 0; i < childNodes.length; i++){
                var childNode = childNodes[i];
                queue.push(childNode);
            }

            while(queue.length > 0){
                var nextNode = queue.top();
                bfs(nextNode);
            }
        }

        /* A bunch of code needed just to map input into adjacency list */
        /**
         * @Tigran
         * There has to be a better way of creating an adjacency list from the input.
         *
         * Perhaps I shouldn't be using an adjacency list data structure or I am
         * over complicating this in some way.
         *
         */
        function getAdjacencyListFromInput(n, p){

            /**
             * Creates [[], ..., []] of size n
             * @param n
             * @returns {Array}
             */
            function createEmptyAdjacencyList(n){
                var adjancencyList = [];
                for(var i = 0; i < n; i++){
                    adjancencyList.push([]);
                }

                return adjancencyList;
            }

            /**
             * Creates array [2, 3, ..., n+1]
             * @param n
             * @returns {Array}
             */

            function createI(n){
                var i = [];
                for(var k = 0; k < n; k++){
                    i.push(k + 2);
                }
                return i;
            }

            var c = createEmptyAdjacencyList(n); // [[], ..., []] of size n
            var i = createI(n); // [2, 3, ... n+1]

            for(var k = 0; k < n-1; k++){
                var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]
                var i_k = i[k]; // e.g. [2, 3, 4, 5, 6]
                c[p_k].push(i_k);
            }

            /**
             *  Above could also be this, but makes it harder to read
             *  */
            // for(var k = 0; k < n-1; k++){
            //     var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]
            //     c[p_k].push(k+2);
            // }

            return c; // e.g. [[], [2, 5], [3, 4], [], [], [6]]
        }

        // currentColors = [0, 0, ..., 0] for size N
        function initializeCurrentColors(n){
            // can't use currentColors var name due to compilation issues in codeforces
            var someColors = new Array(n);
            for(var i=0; i < someColors.length; i++){
                someColors[i] = 0;
            }
            return someColors;
        }

        function addZeroToFrontOfArray(someArray){
            someArray.unshift(0);
        }

        graph = getAdjacencyListFromInput(n, p); // O(n) + O(n) + O(n-1)
        currentColors = initializeCurrentColors(n+1); // O(n)
        addZeroToFrontOfArray(c); // O(n)
        endingColors = c;

        bfs(rootNode); // O(n^2)
        ans = steps;
    }

    var ans = 0;

    const n = parseInt(readline());
    const p = readline().split(" ").map(Number);
    const c = readline().split(" ").map(Number);

    solution(n, p, c);
    print(ans);
}

main();

function main(){
    function solution(n, p, c){
        var graph = [];
        var rootNode = 1;
        var visited = new Set();
        var currentNode = 1;
        var queue = [];
        var currentColors = []; // [0, 0, 0, ..., 0]
        var endingColors = [];
        var steps = 0;
        var colorToPaint = "";

        // var graph = [
        // 	[],
        // 	[2, 5],
        // 	[4, 3],
        // 	[],
        // 	[],
        // 	[6],
        // 	[]
        // ];

        function colorGraph(someNode, someColor){
            if(visited.has(someNode)){
                return;
            }

            currentColors[someNode] = someColor;
            visited.add(someNode);

            var childNodes = graph[someNode];

            if(!childNodes){
                return;
            }

            for(var i = 0; i < childNodes.length; i++){
                var childNode = childNodes[i];
                colorGraph(childNode, someColor);
            }
        }

        var stack = [];

        function colorGraphUsingStack(someNode, someColor){
            stack.push(someNode);

            while(stack.length > 0){
                var current = stack.pop();
                currentColors[current] = someColor;
                var childNodes = graph[current];

                for(var i = 0; i < childNodes.length; i++){
                    var child = childNodes[i];
                    stack.push(child);
                }

            }
        }

        var queueOffset = 0;
        queue.top = function(){
            var top = queue[queueOffset];
            queueOffset++;
            return top;
            //return queue.shift();
        };

        // This operation is O(n), where n is the number of verticies
        function colorsMatch(currentColors, endingColors){
            for(var i = 0; i < endingColors.length; i++){
                if(currentColors[i] !== endingColors[i]){
                    return false;
                }
            }
            return true;
        }

        function bfs(someNode){
            if(colorsMatch(currentColors, endingColors)){
                queue = [];
                return;
            }

            // process current node
            colorToPaint = endingColors[someNode];

            if(currentColors[someNode] !== endingColors[someNode]){
                steps++;
                colorGraphUsingStack(someNode, colorToPaint);
                visited = new Set();
            }

            // get next nodes to process
            var childNodes = graph[someNode];

            if(!childNodes){
                return;
            }

            for(var i = 0; i < childNodes.length; i++){
                var childNode = childNodes[i];
                queue.push(childNode);
            }

            while(queue.length > 0){
                var nextNode = queue.top();
                bfs(nextNode);
            }
        }

        /* A bunch of code needed just to map input into adjacency list */
        /**
         * @Tigran
         * There has to be a better way of creating an adjacency list from the input.
         *
         * Perhaps I shouldn't be using an adjacency list data structure or I am
         * over complicating this in some way.
         *
         */
        function getAdjacencyListFromInput(n, p){

            /**
             * Creates [[], ..., []] of size n
             * @param n
             * @returns {Array}
             */
            function createEmptyAdjacencyList(n){
                var adjancencyList = [];
                for(var i = 0; i < n; i++){
                    adjancencyList.push([]);
                }

                return adjancencyList;
            }

            /**
             * Creates array [2, 3, ..., n+1]
             * @param n
             * @returns {Array}
             */

            function createI(n){
                var i = [];
                for(var k = 0; k < n; k++){
                    i.push(k + 2);
                }
                return i;
            }

            debugger;

            var c = createEmptyAdjacencyList(n + 1); // [[], ..., []] of size n + 1 (where 0 index isn't used)
            var i = createI(n + 1); // [2, 3, ... n+1]

            for(var k = 0; k < n - 1; k++){
                var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]
                var i_k = i[k]; // e.g. [2, 3, 4, 5, 6]
                c[p_k].push(i_k);
            }

            /**
             *  Above could also be this, but makes it harder to read
             *  */
            // for(var k = 0; k < n-1; k++){
            //     var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]
            //     c[p_k].push(k+2);
            // }

            return c; // e.g. [[], [2, 5], [3, 4], [], [], [6]]
        }

        // currentColors = [0, 0, ..., 0] for size N
        function initializeCurrentColors(n){
            // can't use currentColors var name due to compilation issues in codeforces
            var someColors = new Array(n);
            for(var i=0; i < someColors.length; i++){
                someColors[i] = 0;
            }
            return someColors;
        }

        function addZeroToFrontOfArray(someArray){
            someArray.unshift(0);
        }

        graph = getAdjacencyListFromInput(n, p);
        currentColors = initializeCurrentColors(n+1);
        addZeroToFrontOfArray(c);
        endingColors = c;

        bfs(rootNode);
        ans = steps;
        var end = new Date() - start;
    }

    var ans = 0;

    const n = parseInt(readline());
    const p = readline().split(" ").map(Number);
    const c = readline().split(" ").map(Number);

    solution(n, p, c);
    print(ans);
}

var n = 6;
var p = [1, 2, 2, 1, 5];
var c = [2, 1, 1, 1, 1, 1];

function main(){
    function solution(n, p, c){
        var graph = [];
        var rootNode = 1;
        var visited = new Set();
        var currentNode = 1;
        var queue = [];
        var currentColors = []; // [0, 0, 0, ..., 0]
        var endingColors = [];
        var steps = 0;
        var colorToPaint = "";

        // var graph = [
        // 	[],
        // 	[2, 5],
        // 	[4, 3],
        // 	[],
        // 	[],
        // 	[6],
        // 	[]
        // ];

        function colorGraph(someNode, someColor){
            if(visited.has(someNode)){
                return;
            }

            currentColors[someNode] = someColor;
            visited.add(someNode);

            var childNodes = graph[someNode];

            if(!childNodes){
                return;
            }

            for(var i = 0; i < childNodes.length; i++){
                var childNode = childNodes[i];
                colorGraph(childNode, someColor);
            }
        }

        var stack = [];

        function colorGraphUsingStack(someNode, someColor){
            stack.push(someNode);

            while(stack.length > 0){
                var current = stack.pop();
                currentColors[current] = someColor;
                var childNodes = graph[current];

                for(var i = 0; i < childNodes.length; i++){
                    var child = childNodes[i];
                    stack.push(child);
                }

            }
        }

        var queueOffset = 0;
        queue.top = function(){
            var top = queue[queueOffset];
            queueOffset++;
            return top;
            //return queue.shift();
        };

        // This operation is O(n), where n is the number of verticies
        function colorsMatch(currentColors, endingColors){
            for(var i = 0; i < endingColors.length; i++){
                if(currentColors[i] !== endingColors[i]){
                    return false;
                }
            }
            return true;
        }

        function bfs(someNode){
            if(colorsMatch(currentColors, endingColors)){
                queue = [];
                return;
            }

            // process current node
            colorToPaint = endingColors[someNode];

            if(currentColors[someNode] !== endingColors[someNode]){
                steps++;
                colorGraphUsingStack(someNode, colorToPaint);
                visited = new Set();
            }

            // get next nodes to process
            var childNodes = graph[someNode];

            if(!childNodes){
                return;
            }

            for(var i = 0; i < childNodes.length; i++){
                var childNode = childNodes[i];
                queue.push(childNode);
            }

            while(queue.length > 0){
                var nextNode = queue.top();
                bfs(nextNode);
            }
        }

        /* A bunch of code needed just to map input into adjacency list */
        /**
         * @Tigran
         * There has to be a better way of creating an adjacency list from the input.
         *
         * Perhaps I shouldn't be using an adjacency list data structure or I am
         * over complicating this in some way.
         *
         */
        function getAdjacencyListFromInput(n, p){

            /**
             * Creates [[], ..., []] of size n
             * @param n
             * @returns {Array}
             */
            function createEmptyAdjacencyList(n){
                var adjancencyList = [];
                for(var i = 0; i < n; i++){
                    adjancencyList.push([]);
                }

                return adjancencyList;
            }

            /**
             * Creates array [2, 3, ..., n+1]
             * @param n
             * @returns {Array}
             */

            function createI(n){
                var i = [];
                for(var k = 0; k < n; k++){
                    i.push(k + 2);
                }
                return i;
            }

            debugger;

            var c = createEmptyAdjacencyList(n + 1); // [[], ..., []] of size n + 1 (where 0 index isn't used)
            var i = createI(n + 1); // [2, 3, ... n+1]

            for(var k = 0; k < n - 1; k++){
                var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]
                var i_k = i[k]; // e.g. [2, 3, 4, 5, 6]
                c[p_k].push(i_k);
            }

            /**
             *  Above could also be this, but makes it harder to read
             *  */
            // for(var k = 0; k < n-1; k++){
            //     var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]
            //     c[p_k].push(k+2);
            // }

            return c; // e.g. [[], [2, 5], [3, 4], [], [], [6]]
        }

        // currentColors = [0, 0, ..., 0] for size N
        function initializeCurrentColors(n){
            // can't use currentColors var name due to compilation issues in codeforces
            var someColors = new Array(n);
            for(var i=0; i < someColors.length; i++){
                someColors[i] = 0;
            }
            return someColors;
        }

        function addZeroToFrontOfArray(someArray){
            someArray.unshift(0);
        }

        graph = getAdjacencyListFromInput(n, p);
        currentColors = initializeCurrentColors(n+1);
        addZeroToFrontOfArray(c);
        endingColors = c;

        bfs(rootNode);
        ans = steps;
    }

    var ans = 0;

    const n = parseInt(readline());
    const p = readline().split(" ").map(Number);
    const c = readline().split(" ").map(Number);

    solution(n, p, c);
    print(ans);
}


'use strict'

const problem = (n, k, p) => {
    for(let i = 0, j = 0; i < p.length; i++) {
        if (p[i]) continue;
        if (i === j) { j++; continue; }
        p[i] = 1;
        if (k <= i - j) { p[i-k] = 0; return p.join(''); }
        k -= (i - j);
        p[j++] = 0;
    }
    return p.join('');
}

let q = +readline();
while (q--) {
    const nk = readline().split(' ').map(Number);
    const p = readline().split('').map(Number);
    print(problem(nk[0], nk[1], p));
}

let fs = require("fs");

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    doit(info[1] * 1, txt[index + 1]);
}

function doit(b, str) {
    let tab = str.split("");
    tab.map((data, index) => {
        if (data == 0) {
            return index;
        }
    }).filter(data => {
        return data != undefined
    }).forEach((data, index) => {
        if(b>0){
            tab[data]=1;
           if(data-index<=b){
                tab[index]=0;
                b-=data-index;
           }else{
               tab[data-b]=0;
                b=0;
               return;
           }
        }
    })
    console.log(tab.join(""));
}

'use strict'

const problem = (n, k, p) => {
    let a = 0, b;
    const z = p.reduce((r, i, j) => { if (!i) r.push(j); return r; }, []);
    while (b = z.shift()) {
        if (k <= (b - a)) { p[b] = 1; p[b-k] = 0; return p.join('')}
        p[b] = 1; k -= (b - a); p[a++] = 0;
    }
    return p.join('');
}

let q = +readline();
while (q--) {
    const nk = readline().split(' ').map(Number);
    const p = readline().split('').map(Number);
    print(problem(nk[0], nk[1], p));
}

'use strict'

const problem = (n, k, p) => {
    for(let i = 0, j = 0; i < p.length; i++) {
        if (p[i] || i === j) continue;
        p[i] = 1;
        if (k <= i - j) { p[i-k] = 0; return p.join(''); }
        k -= (i - j);
        p[j++] = 0;
    }
    return p.join('');
}

let q = +readline();
while (q--) {
    const nk = readline().split(' ').map(Number);
    const p = readline().split('').map(Number);
    print(problem(nk[0], nk[1], p));
}

'use strict'

const problem = (n, k, p) => {
    let a = 0, b;
    while ((b = p.slice(a).indexOf(0)) !== -1) {
        if (k < b) { p[a+b-k] = 0; p[a+b] = 1; return p.join('')}
        p[a+b] = 1; p[a++] = 0;k -= b;
    }
    return p.join('');
}

let q = +readline();
while (q--) {
    const nk = readline().split(' ').map(Number);
    const p = readline().split('').map(Number);
    print(problem(nk[0], nk[1], p));
}

'use strict'

const problem = (n, k, p) => {
    for(let i = 0, j = 0; i < p.length; i++) {
        if (p[i]) continue;
        if (i === j) { j++; continue; }
        p[i] = 1;
        if (k <= i - j) { p[i-k] = 0; return p.join(''); }
        k -= (i - j);
        p[j++] = 0;
        print(i, j-1, k, p.join(''))
    }
    return p.join('');
}

let q = +readline();
while (q--) {
    const nk = readline().split(' ').map(Number);
    const p = readline().split('').map(Number);
    print(problem(nk[0], nk[1], p));
}

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    let tab = txt[index + 1].split("").filter(data => {
        return data.length > 0
    });
    binary(info[1] * 1, tab)

}

function binary(x, tab) {
    tab.map((data, index) => {
        return (data == 0) ? index : null;
    }).filter(data => {
        return data;
    }).forEach((data, index) => {
        while (data != index && x > 0) {
            tab[data] = 1;
            tab[data - 1] = 0;
            --x;
            --data;
        }
    });
    console.log(tab.join(""));
}

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    let tab = txt[index + 1].split("").filter(data => {
        return data.length > 0
    });
    binary(info[1] * 1, tab)

}

function binary(x, tab) {
    let pos=-1;
    for (let i = 0; i < tab.length; i++) {
        if(tab[i]==0){
            ++pos;
            if(i!=pos && x>0){
                tab[i]=1;
                if(x>=i-1){
                    tab[pos]=0;
                    x-=i-pos;
                }else{
                    tab[i-x]=0;
                    break;
                }
            }
        }

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

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    let tab = txt[index + 1].split("").filter(data => {
        return data.length > 0
    });
    binary(info[1] * 1, tab)

}

function binary(x, tab) {
   let pos=0;
   for (let index = 0; index < tab.length; index++) {
      if(tab[index]==0 && index!=pos){
          tab[index]=1;
          if(x-index>=0){
              tab[pos]=0;
              x-=index;
              ++pos;
          }else{
              tab[index-x]=0;
              break;
          }
      }

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

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    let tab = txt[index + 1].split("").filter(data => {
        return data.length > 0
    });
    binary(info[1] * 1, tab)

}

function binary(x, tab) {
   let pos=0;
   for (let index = 0; index < tab.length; index++) {
      if(tab[index]==0 && index!=pos){
          tab[index]=1;
          if(x-index>=0){
              tab[pos]=0;
              x-=index;
              ++pos;
          }else{
              tab[index-x]=0;
             x=0;
          }
          if(x==0){
              break;
          }
      }

   }
    console.log(tab.join(""));
}
// 01011110
// 0101111
// 0011111

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    binary(info[1] * 1, txt[index+1])

}

function binary(x, tab) {
    let pos=0;
    let arr=new Array(tab.length).fill(1);
    for (let i = 0; i < tab.length; i++) {
        if(tab[i]==0){
            if(i-pos<=x){
                x-=Math.abs(pos-i);
                arr[pos]=0;
            }else{
                arr[i-x]=0;
                x=0
            }
            if(x<=0){
                break;
            }
            ++pos
        }

    }
    console.log(arr.join(""));
}
// 01011110
// 0101111
// 0011111

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    let tab = txt[index + 1].split("").filter(data => {
        return data.length > 0
    });
    binary(info[1] * 1, tab)

}

function binary(x, tab) {
   let pos=0;
   for (let index = 0; index < tab.length; index++) {
      if(tab[index]==0 && index!=pos){
          tab[index]=1;
          if(x-index>=pos){
              tab[pos]=0;
              x-=index;
              ++pos;
          }else{
              tab[index-x]=0;
             x=0;
          }
          if(x==0){
              break;
          }
      }

   }
    console.log(tab.join(""));
}
// 01011110
// 0101111
// 0011111

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    binary(info[1] * 1, txt[index+1])

}

function binary(x, tab) {
    let pos=0;
    let arr=new Array(tab.length).fill(1);
    for (let i = 0; i < tab.length; i++) {
        if(tab[i]==0){
            if(i-pos<=x){
                x-=i-pos;
                arr[pos]=0;
            }else{
                arr[i-x]=0;
                x=0
            }
            if(x==0){
                break;
            }
            ++pos
        }

    }
    console.log(arr.join(""));
}
// 01011110
// 0101111
// 0011111

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    let tab = txt[index + 1].split("").filter(data => {
        return data.length > 0
    });
    binary(info[1] * 1, tab)

}

function binary(x, tab) {
   tab.map((data, index) => {
        return (data == 0) ? index : undefined;
    }).filter(data => {
        return data != undefined;
    }).forEach((data, index) => {
        if(x==0){
            return;
        }else if(data!=index){
           tab[data]=1;
           if(data<=x){
               tab[index]=0;
               x-=data-index;
           }else{
               tab[data-x]=0;
               return;
           }
        }
    });
    console.log(tab.join(""));
}

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    let tab = txt[index + 1].split("").filter(data => {
        return data.length > 0
    });
    binary(info[1] * 1, tab)

}

function binary(x, tab) {
    let r = tab.map((data, index) => {
        return (data == 0) ? index : undefined;
    }).filter(data => {
        return data != undefined;
    }).forEach((data, index) => {
       if(data!=index && x!=0){
           tab[data]=1;
            if(x>=data-index){
                tab[index]=0;
                x-=data;
            }else{
                tab[data-x]=0;
                x=0;
            }
       }
    });
    console.log(tab.join(""));
}

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    let tab = txt[index + 1].split("").filter(data => {
        return data.length > 0
    });
    binary(info[1] * 1, tab)

}

function binary(x, tab) {
   tab.map((data, index) => {
        return (data == 0) ? index : undefined;
    }).filter(data => {
        return data != undefined;
    }).forEach((data, index) => {
        if(x==0){
            return;
        }else if(data!=index){
           tab[data]=1;
           if(data<x){
               tab[index]=0;
               x-=data-index;
           }else{
               tab[data-x]=0;
               return;
           }
        }
    });
    console.log(tab.join(""));
}

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    binary(info[1] * 1, txt[index+1])

}

function binary(x, tab) {
    let pos=0;
    let arr=new Array(tab.length).fill(1);
    for (let i = 0; i < tab.length; i++) {
        if(tab[i]==0){
            if(i-pos<=x){
                x-=Math.abs(pos-i);
                arr[pos]=0;
            }else{
                arr[i-x]=0;
                break;
            }
            ++pos
        }

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

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    let tab = txt[index + 1].split("").filter(data => {
        return data.length > 0
    });
    binary(info[1] * 1, tab)

}

function binary(x, tab) {
   let pos=0;
   for (let index = 0; index < tab.length; index++) {
      if(tab[index]==0 && index!=pos){
          tab[index]=1;
          if(index-pos<=x){
              tab[pos]=0;
              x-=index;
              ++pos;
          }else{
              tab[index-x]=0;
             x=0;
          }
          if(x==0){
              break;
          }
      }

   }
    console.log(tab.join(""));
}
// 01011110
// 0101111
// 0011111

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    binary(info[1] * 1, txt[index+1])

}

function binary(x, tab) {
    let pos=0;
    let arr=new Array(tab.length).fill(1);
    for (let i = 0; i < tab.length; i++) {
        if(tab[i]==0){
            if(i-pos<=x){
                x-=Math.abs(pos-i);
                arr[pos]=0;
            }else{
                arr[i-x]=0;
            }
            if(x<=0){
                break;
            }
            ++pos
        }

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

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
txt.shift();
for (let index = 0; index < txt.length; index += 2) {
    let info = txt[index].split(" ")
    binary(info[1] * 1, txt[index+1])

}

function binary(x, tab) {
    let pos=0;
    let arr=new Array(tab.length).fill(1);
    for (let i = 0; i < tab.length; i++) {
        if(tab[i]==0){
            arr[i]=1;
            if(i-pos<=x){
                x-=Math.abs(pos-i);
                arr[pos]=0;
            }else{
                arr[i-x]=0;
                x=0;
                break;
            }
            ++pos
        }

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


"use strict";

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

let inputString = "";
let currentLine = 0;

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

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

	main();
});

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

function isPossible(op, sum, arr, n, k) {
	var pref = 0;
	for (let i = n - 1; i > 0; i--) {
		var extra = arr[i] - arr[0];
		pref += extra;
		if (sum - 1 <= k) return true;
		op--;
		var minSumPossible = sum - pref - op * (n - i + 1);
		if (minSumPossible <= k) return true;
		if (op == 0) return false;
	}
	return false;
}

function solve() {
	var [n, k] = readLine().trim().split(" ").map(Number);
	var arr = readLine().trim().split(" ").map(Number);
	arr.sort((a, b) => a - b);
	var sum = arr.reduce((ac, now) => ac + now, 0);
	if (sum <= k) return 0;
	if (n == 1) {
		return arr[0] - k;
	}
	//sorry that line was written by mistake, wondering how it worked then?
	//var have a global lexical scope
	var l = 1,
		r = 1e12;
	while (l < r) {
		var mid = Math.floor((l + r) / 2);
		if (isPossible(mid, sum, arr, n, k)) {
			r = mid;
		} else {
			l = mid + 1;
		}
	}
	return r;
}

function main() {
	var t = +readLine();
	while (t--) {
		console.log(solve());
	}
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, k, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, k, arr) {
    arr.sort((a, b) => a - b)
// console.log(arr)
    const sum = arr.reduce((s, x) => s + x, 0)
    if (sum <= k) return 0

    let b = 0
    let s = 0
    let ans = sum - k
    for (let i = arr.length - 1; i >= 1; i--) {
        b++
        s += arr[i] - arr[0]
        const d = sum - k - s
        // a + ab + s >= sum - k
        const a = d <= 0 ? 0 : Math.ceil(d / (b + 1))
        // console.log(s, d, a, b, (a + a * b + s))
        ans = Math.min(ans, a + b)
    }
    return ans
}

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

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

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const sumab = (a, b) => {
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return BigInt(x) * BigInt(y);
}

const calc = (n, k, a) => {
    a = a.sort((x, y) => x - y);
    let sum = 0;
    let pref = new Array(n).fill(0);
    let min = a[0];
    pref[0] = a[0];
    for (let i = 0; i < n; i++) {
        sum += a[i];
        if (i > 0) pref[i] = pref[i - 1] + a[i];
    }

    if (sum <= k) return 0;
    let result = sum - k;
    if (n === 1) return result;

    for (let swaps = 0; swaps < n; swaps++) {
        let firstSwapped = n - swaps;
        let othersum = pref[firstSwapped - 1] - pref[0];
        let targetNum = Math.floor((k - othersum) / (swaps + 1) + 0.0001);
        let minusops = a[0] - targetNum;
        result = Math.min(result, Math.max(minusops, 0) + swaps);
    }
    return result;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let [n, k] = ra();
        let a = ra();
        console.log(`${calc(n, k, a)}`);
    }
}

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

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

		let sum = 0;
		for (let i = 0; i < n; i++) sum += a[i];
		const excess = Math.max(0, sum - k);
		a.sort((x, y) => y - x);

		let ans = 1e18;
		for (let i = 1, vcur = 0; i <= n; i++) {
			const d = Math.max(0, Math.ceil((excess - vcur) / i));
			ans = Math.min(ans, d + i - 1);
			vcur += a[i-1] - a[n-1];
		}

		console.log(ans);
	}
}

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

let solve = async () => {
    const nsc = parseInt(await getLine());
    for(let sc = 0; sc < nsc; sc++) {
        const [n,k] = (await getLine()).split(' ').map(num => parseInt(num));
        const a = (await getLine()).split(' ').map(num => parseInt(num));
        a.sort((a,b) => (a - b));
        const sum = new Array(n);
        for(let i = 0; i < n; i++) {
            sum[i] = a[i];
            if (i > 0)
                sum[i] += sum[i - 1];
        }
        if (sum[n - 1] <= k) {
            console.log('0');
            continue;
        }
        let best = sum[n - 1] - k;
        for(let i = 1; i < n; i++) {
            let left = sum[i-1] - sum[0];
            let leftCount = n - (i - 1);
            let need = Math.floor((k - left) / leftCount);
            let try1 = 0;
            if (a[0] > need)
                try1 = a[0] - need;
            best = Math.min(best, try1 + n - i);
        }

        console.log(best);
    }
}

solve();

"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 isPossible(op, sum, arr, n, k) {
	var pref = 0;
	for (let i = n - 1; i > 0; i--) {
		var extra = arr[i] - arr[0];
		pref += extra;
		if (sum - 1 <= k) return true;
		op--;
		var minSumPossible = sum - pref - op * (n - i + 1);
		if (minSumPossible <= k) return true;
		if (op == 0) return false;
	}
	return false;
}

function solve() {
	var [n, k] = readLine().trim().split(" ").map(Number);
	var arr = readLine().trim().split(" ").map(Number);
	arr.sort((a, b) => a - b);
	var sum = arr.reduce((ac, now) => ac + now, 0);
	if (sum <= k) return 0;
	if (n == 1) {
		return arr[0] - k;
	}
	if (sum - 1)
		var l = 1,
			r = 1e12;
	while (l < r) {
		var mid = Math.floor((l + r) / 2);
		if (isPossible(mid, sum, arr, n, k)) {
			r = mid;
		} else {
			l = mid + 1;
		}
	}
	return r;
}

function main() {
	var t = +readLine();
	while (t--) {
		console.log(solve());
	}
}

"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 isPossible(op, sum, arr, n, k) {
	var pref = 0;
	for (let i = n - 1; i > 0; i--) {
		var extra = arr[i] - arr[0];
		pref += extra;
		if (sum - 1 <= k) return true;
		op--;
		var minSumPossible = sum - pref - op * (n - i + 1);
		if (minSumPossible <= k) return true;
		if (op == 0) return false;
	}
	return false;
}

function solve() {
	var [n, k] = readLine().trim().split(" ").map(Number);
	var arr = readLine().trim().split(" ").map(Number);
	arr.sort((a, b) => a - b);
	var sum = arr.reduce((ac, now) => ac + now, 0);
	if (sum <= k) return 0;
	if (n == 1) {
		return arr[0] - k;
	}
	if (sum - 1)
		var l = 1,
			r = 1e9;
	while (l < r) {
		var mid = Math.floor((l + r) / 2);
		if (isPossible(mid, sum, arr, n, k)) {
			r = mid;
		} else {
			l = mid + 1;
		}
	}
	return r;
}

function main() {
	var t = +readLine();
	while (t--) {
		console.log(solve());
	}
}

"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 isPossible(op, sum, arr, n, k) {
	var pref = 0;
	for (let i = n - 1; i > 0; i--) {
		var extra = arr[i] - arr[0];
		pref += extra;
		op--;
		var minSumPossible = sum - pref - op * (n - i + 1);

		if (minSumPossible <= k) return true;
		if (op == 0) return false;
	}
	return false;
}

function solve() {
	var [n, k] = readLine().trim().split(" ").map(Number);
	var arr = readLine().trim().split(" ").map(Number);
	arr.sort((a, b) => a - b);
	var sum = arr.reduce((ac, now) => ac + now, 0);
	if (sum <= k) return 0;
	if (n == 1) {
		return arr[0] - k;
	}
	var l = 1,
		r = 1e9;
	while (l < r) {
		var mid = Math.floor((l + r) / 2);
		if (isPossible(mid, sum, arr, n, k)) {
			r = mid;
		} else {
			l = mid + 1;
		}
	}
	return r;
}

function main() {
	var t = +readLine();
	while (t--) {
		console.log(solve());
	}
}

"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 isPossible(op, sum, arr, n, k) {
	var pref = 0;
	for (let i = n - 1; i > 0; i--) {
		var extra = arr[i] - arr[0];
		pref += extra;
		op--;
		var minSumPossible = sum - pref - op * (n - i + 1);

		if (minSumPossible <= k) return true;
		if (op == 0) return false;
	}
	return false;
}

function solve() {
	var [n, k] = readLine().trim().split(" ").map(Number);
	var arr = readLine().trim().split(" ").map(Number);
	arr.sort((a, b) => a - b);
	var sum = arr.reduce((ac, now) => ac + now, 0);
	if (sum <= k) return 0;

	var l = 1,
		r = 1e9;
	while (l < r) {
		var mid = Math.floor((l + r) / 2);
		if (isPossible(mid, sum, arr, n, k)) {
			r = mid;
		} else {
			l = mid + 1;
		}
	}
	return r;
}

function main() {
	var t = +readLine();
	while (t--) {
		console.log(solve());
	}
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, k, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, k, arr) {
    arr.sort((a, b) => a - b)
// console.log(arr)
    const sum = arr.reduce((s, x) => s + x, 0)
    if (sum <= k) return 0

    let b = 0
    let s = 0
    let ans = sum - k
    for (let i = arr.length - 1; i >= 1; i--) {
        b++
        s += arr[i] - arr[0]
        const d = sum - k - s
        // a + ab + s >= sum - k
        const a = Math.ceil(d / (b + 1))
        // console.log(s, d, a, b, (a + a * b + s))
        ans = Math.min(ans, a + b)
    }
    return ans
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, k, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, k, arr) {
    arr.sort((a, b) => a - b)
// console.log(arr)
    const sum = arr.reduce((s, x) => s + x, 0)
    if (sum <= k) return 0

    let b = 0
    let s = 0
    let ans = sum - k
    for (let i = arr.length - 1; i >= 1; i--) {
        b++
        const d = sum - k - s
        // a + ab + s >= sum - k
        const a = Math.floor(d / (b + 1))
        // console.log(s, d, a, b)
        ans = Math.min(ans, a + b)

        s += arr[i] - arr[0]
    }
    return ans
}

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

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

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const sumab = (a, b) => {
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return BigInt(x) * BigInt(y);
}

const calc = (n, k, a) => {
    a = a.sort((x, y) => x - y);
    let sum = 0;
    let pref = new Array(n).fill(0);
    let min = a[0];
    pref[0] = a[0];
    for (let i = 0; i < n; i++) {
        sum += a[i];
        if (i > 0) pref[i] = pref[i - 1] + a[i];
    }

    if (sum <= k) return 0;
    let result = sum - k;
    if (n === 1) return result;

    for (let swaps = 0; swaps < n; swaps++) {
        let firstSwapped = n - swaps;
        let othersum = pref[firstSwapped - 1] - pref[0];
        let targetNum = Math.floor((k - othersum) / (swaps + 1) + 0.0001);
        let minusops = a[0] - targetNum;
        result = Math.min(result, minusops + swaps);
    }
    return result;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let [n, k] = ra();
        let a = ra();
        console.log(`${calc(n, k, a)}`);
    }
}


var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

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

function main () {
	let T = rn();
	while (T--) {
		const [l, r] = rna();

		function countChanges (n) {
			let res = 0, k = 0;
			while (n) {
				k = k * 10 + 1;
				res += n % 10 * k;
				n = Math.floor(n / 10);
			}
			return res;
		}

		const ans = countChanges(r) - countChanges(l);
		console.log(ans);
	}
}

'use strict';

function solve(n, m) {
  const dp = [1, 11];
  for (let i = 2; i <= 9; i++) {
    dp[i] = dp[i - 1] * 10 + 1;
  }
  let res = 0,
      t = m;
  for (let i = 9; i >= 0; i--) {
    const j = Math.floor(t / 10 ** i);
    res += dp[i] * j;
    t -= 10 ** i * j;
  }
  t = n;
  for (let i = 9; i >= 0; i--) {
    const j = Math.floor(t / 10 ** i);
    res -= dp[i] * j;
    t -= 10 ** i * j;
  }
  return res;
}

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

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

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        console.log(solve(lines[l++].split(' ')));
    }
});

function solve([a, b]) {
    return f(b) - f(a)
}

function f(str) {
    const chs = str.split('').reverse().map(Number)
    let base = 10 + 1
    const factor = [0] // for 10^i
    for (let i = 0; i < chs.length; i++) {
        factor.push(base)
        base = base * 10 + 1
    }

    let sum = 0
    for (let i = 0; i < chs.length; i++) {
        const x = chs[i]
        if (i) {
            sum += x * factor[i]
        } else {
            sum += x
        }
    }
    return sum
}

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

function main(){
	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {

		var lr = readNumArray();

		var n1 = lr[0];
		var n2 = lr[1];

		var digits = 0;

		while(n1 !== 0 || n2 !== 0){
			digits = digits + (n2 - n1);
			n1 = Math.floor(n1/10);
			n2 = Math.floor(n2/10);
		}

		print(digits);

	}
}

main();


'use strict';
// node.js
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() {
    var testCases = parseInt(readLine());

    for (var i = 0; i < testCases; i++) {
        var numbers = readLine()
            .split(" ")
            .map(num => parseInt(num));

        var rows = numbers[0];
        var columns = numbers[1];
        var rowsAvaiable = Array(rows).fill(true);
        var columnsAvaiable = Array(columns).fill(true);

        for (let j = 0; j < rows; j++) {
            readLine()
                .split(" ")
                .map(num => parseInt(num))
                .forEach((number, index) => {
                    // console.log(number, index);
                    if (number == 1) {
                        rowsAvaiable[j] = false;
                        columnsAvaiable[index] = false;
                    }
                });
        }
        console.log(
            Math.min(
                rowsAvaiable.filter(value => value == true).length,
                columnsAvaiable.filter(value => value == true).length
            ) % 2 ? "Ashish" : "Vivek"
        );
    }
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nm = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nm[0],
    m = nm[1];
  var cells = [];
  var rows = new Array(n).fill(1);
  var col = new Array(m).fill(1);
  for (var i = 0; i < n; i++) {
    var r = readline()
      .split(" ")
      .map((val, ind) => {
        val = parseInt(val);
        if (val == 1) {
          rows[i] = 0;
          col[ind] = 0;
          return val;
        }
      });
  }

  var myCount1 = 0;
  for (var i = 0; i < n; i++) {
    if (rows[i] == 1) myCount1++;
  }

  var myCount2 = 0;
  for (var i = 0; i < m; i++) {
    if (col[i] == 1) myCount2++;
  }

  if (Math.min(myCount1, myCount2) % 2 == 0) print("Vivek");
  else print("Ashish");
}

var t = readline().split(" ").map(function(x) { return parseInt(x); })[0];

var step = () => {
  var inp = readline().split(" ").map(function(x) { return parseInt(x); });
  var n = inp[0];
  var m = inp[1];
  var rows = new Array(n);
  var columns = new Array(m);

  for(var i1 = 0; i1 < n; i1++){
    rows [i1] = 0;
  }
  for(var j1 = 0; j1 < m; j1++){
    columns[j1] = 0;
  }

  for(var i = 0; i < n; i++){
    var row = readline().split(" ").map(function(x) { return parseInt(x); });
    for(var j = 0; j < m; j++){
      if(row[j] == 1){
        columns[j] = 1;
        rows[i] = 1;
      }
    }
  }

  var freeRows = rows.reduce((p, c) => c == 1 ? p : p+1, 0);
  var freeColumnss = columns.reduce((p, c) => c == 1 ? p : p+1, 0);

  var minV = Math.min(freeColumnss, freeRows);

  if(minV % 2 == 0){
    print("Vivek")
  }
  else{
    print("Ashish")
  }

}

for(var i2 = 0; i2 < t; i2++){
  step();
}

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

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var nm = readNumArray();
    var n = nm[0];
    var m = nm[1];
    var nC = new Set();
    var mC = new Set();
    for (var j = 0; j < n; j++) {
      var currN = readNumArray();
      for (var k = 0; k < m; k++) {
        if (currN[k]) {
          mC.add(k);
          nC.add(j);
        }
      }
    }
    var steps = Math.min(n - nC.size, m - mC.size);

    print(steps % 2 ? "Ashish" : "Vivek");
  }
}

main();

// const bg = require('big-integer')
process.stdin.resume()
process.stdin.setEncoding('utf-8')
const MOD1 = 1000000007

function alpha(c = 'A') {
  return [...{
    _b: c === 'A' ? 65 : 97,
    _i: -1,
    [Symbol.iterator]() {
      return this
    },
    next() {
      this._i++
      if (this._i === 26) return {done: true}
      else return {done: false, value: String.fromCharCode(this._i + this._b)}
    }
  }]
}

class rc {
  static construct() {
    this.input = ''
    this.ptr = 0
  }
  static readString() {
    return this.input[this.ptr++]
  }

  static readStrings() {
    return this.input[this.ptr++].split(' ')
  }

  static readInt() {
    return +this.readString()
  }

  static readInts() {
    return this.readStrings().map(a => +a)
  }

  static readBigInteger() {
    return bg(this.readString())
  }

  static readBigIntegers() {
    return this.readStrings().map(a => bg(a))
  }
}

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

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

rc.construct()
// bc.construct()
process.stdin.on('data', (i) => {
  rc.input += i
})

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

function main() {
  let t = rc.readInt()
  while (t--) {
    const [n, m] = rc.readInts()
    const a = new Array(n)
    let count1 = 0
    for(let i = 0; i < n; i++) {
      a[i] = rc.readInts()
      let x = a[i].includes(1)
      if(x) count1++
    }

    let count2 = 0
    for(let i = 0; i < m; i++) {
      for(let j = 0; j < n; j++) {
        if(a[j][i] === 1) {
          count2++
          break
        }
      }
    }

    let diff = Math.min(n - count1, m - count2)

    // wr(count1, count2)

    if((diff & 1) === 0) wr('Vivek')
    else wr('Ashish')
  }

}

//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
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;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var M = one[1];
		var list = new Array(N);
		var used = new Set();
		for(var j = 0; j < N; j++){
			list[j] = nextStrArray();
		}
		var turn = true;//true:Asish,false:Vivek
		while(true){
			if(turn){
				var isChange = false;
				for(var j = 0; j < N; j++){
					if(isChange){
						break;
					}
					for(var k = 0; k < M; k++){
						if(isChange){
							break;
						}
						if(list[j][k] == "0"){
							var isNG = false;
							for(var l = 0; l < N; l++){
								if(list[l][k] == "1"){
									isNG = true;
									break;
								}
							}
							for(var l = 0; l < M; l++){
								if(list[j][l] == "1"){
									isNG = true;
									break;
								}
							}
							if(!isNG){
								list[j][k] = "1";
								isChange = true;
							}
						}
					}
				}
				if(isChange){
					turn = false;
				}else{
					break;
				}
			}else{
				var isChange = false;
				for(var j = 0; j < N; j++){
					if(isChange){
						break;
					}
					for(var k = 0; k < M; k++){
						if(isChange){
							break;
						}
						if(list[j][k] == "0"){
							var isNG = false;
							for(var l = 0; l < N; l++){
								if(list[l][k] == "1"){
									isNG = true;
									break;
								}
							}
							for(var l = 0; l < M; l++){
								if(list[j][l] == "1"){
									isNG = true;
									break;
								}
							}
							if(!isNG){
								list[j][k] = "1";
								isChange = true;
							}
						}
					}
				}
				if(isChange){
					turn = true;
				}else{
					break;
				}
			}
		}
		if(turn){
			output[i] = "Vivek";
		}else{
			output[i] = "Ashish";
		}
	}
	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.shift() * 1;
  let i = 0;
  while (i < testCases) {
    let int = data.shift().split(' ');
    let col = int[1] * 1;
    let row = int[0] * 1;
    let arr = [];
    let player = 0;
    let idxC = {};
    for (let j = 0; j < row; j += 1) arr.push(data.shift().slice(0, -1).split(' '));
    for (let j = 0; j < arr.length; j += 1) {
      let idx = arr[j].indexOf('1');
      if (idx < 0) {
        let k = 0;
        i1:
        while (k < col) {
          if (!idxC[k]) {
            let check = true;
            for (let r = 0; r < row; r += 1) {
              if (arr[r][k] === '1') {idxC[k] = 1; k += 1; continue i1;}
            }
            arr[j][k] = '1';
            idxC[k] = 1;
            player += 1;
            break;
          }
          k += 1;
        }
      } else idxC[idx] = 1;
    }
    const result = (player & 1) === 0 ? 'Vivek' : 'Ashish';
    console.log(result);
    i += 1;
  }
}

const processData = (lines) => {
  let acc = 0
  const n = +lines[acc]
  acc++
  for (let i=0; i<n; i++) {
    const [n, m] = lines[acc].split(' ').map(x => +x)
    const l = {x: new Array(m).fill(0), y: new Array(n).fill(0)}
    let it = 0
    acc++
    while(it<n) {
      const arr = lines[acc].split(' ').map(x => +x)
      for (let i =0; i<arr.length; i++) {
        if (arr[i] === 1) {
          l.y[it] = 1
          l.x[i] = 1
        }
      }
      it++
      acc++
    }
    const sumX = l.x.reduce((r, x) => r+x, 0)
    const sumY = l.y.reduce((r, x) => r+x, 0)
    const pos = Math.min(n - sumY, m - sumX)
    console.log(pos % 2 === 0? 'Vivek' : 'Ashish')
  }
}

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

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

var N = null,
    init = true,
    n = 0,
    m = 0,
    r, u, w

function initMatrix(line) {
    const size = line.split(" ").map(x => parseInt(x,10))
    u = new Set()
    w = new Set()
    n = size[0]
    m = size[1]
    r = 0
    init = false
}

function inputRow(line) {
    for (let c=0;c<2*m;c=c+2) {
        if (line[c] == "1") {
            u.add(r)
            w.add(c)
        }
    }
    if (++r == n) {
        n -= u.size
        m -= w.size

        console.log((m < n ? m : n)%2 == 1 ? "Ashish":"Vivek")
        init = --N == 0 ? rl.close() : true
    }
}

function loop(line) {
    if (line.trim() == "") return
    (init ? initMatrix : inputRow)(line)
}

rl.question("", line => {
    N = parseInt(line,10)
    rl.on("line", loop)
})

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nm = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nm[0],
    m = nm[1];
  var cells = [];
  var rows = new Array(n).fill(1);
  var col = new Array(m).fill(1);
  for (var i = 0; i < n; i++) {
    var r = readline()
      .split(" ")
      .map((val, ind) => {
        val = parseInt(val);
        if (val == 1) {
          rows[i] = 0;
          col[ind] = 0;
          return val;
        }
      });
  }

  var myCount1 = 0;
  for (var i = 0; i < n; i++) {
    if (rows[i] == 1) myCount1++;
  }

  var myCount2 = 0;
  for (var i = 0; i < n; i++) {
    if (col[i] == 1) myCount2++;
  }

  if (Math.min(myCount1, myCount2) % 2 == 0) print("Vivek");
  else print("Ashish");
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nm = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nm[0],
    m = nm[1];
  var cells = [];
  var rows = new Array(n).fill(1);
  var col = new Array(m).fill(1);
  for (var i = 0; i < n; i++) {
    var r = readline()
      .split(" ")
      .map((val, ind) => {
        val = parseInt(val);
        if (val == 1) {
          rows[i] = 0;
          col[ind] = 0;
          return val;
        }
      });
  }

  if (n <= m) {
    var myCount = 0;
    for (var i = 0; i < n; i++) {
      if (rows[i] == 1) myCount++;
    }
  } else {
    var myCount = 0;
    for (var i = 0; i < n; i++) {
      if (col[i] == 1) myCount++;
    }
  }
  if (n == 1 || m == 1) {
    if (myCount == 0) print("Vivek");
    else print("Ashish");
  } else {
    if (myCount % 2 == 0) print("Vivek");
    else print("Ashish");
  }
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nm = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nm[0],
    m = nm[1];
  var cells = [];
  var rows = new Array(n).fill(1);
  var col = new Array(m).fill(1);
  for (var i = 0; i < n; i++) {
    var r = readline()
      .split(" ")
      .map((val, ind) => {
        val = parseInt(val);
        if (val == 1) {
          rows[i] = 0;
          col[ind] = 0;
          return val;
        }
      });
  }
  if (n >= m) {
    var myCount = 0;
    for (var i = 0; i < n; i++) {
      if (rows[i] == 1) myCount++;
    }
  } else {
    var myCount = 0;
    for (var i = 0; i < n; i++) {
      if (col[i] == 1) myCount++;
    }
  }

  if (myCount % 2 == 0) print("Vivek");
  else print("Ashish");
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nm = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nm[0],
    m = nm[1];
  var cells = [];
  var rows = new Array(n).fill(1);
  var col = new Array(m).fill(1);
  for (var i = 0; i < n; i++) {
    var r = readline()
      .split(" ")
      .map((val, ind) => {
        val = parseInt(val);
        if (val == 1) {
          rows[i] = 0;
          col[ind] = 0;
          return val;
        }
      });
  }
  if (n <= m) {
    var myCount = 0;
    for (var i = 0; i < n; i++) {
      if (rows[i] == 1) myCount++;
    }
  } else {
    var myCount = 0;
    for (var i = 0; i < n; i++) {
      if (col[i] == 1) myCount++;
    }
  }

  if (myCount % 2 == 0) print("Vivek");
  else print("Ashish");
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nm = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nm[0],
    m = nm[1];
  var cells = [];
  var rows = new Array(n).fill(1);
  var col = new Array(m).fill(1);
  for (var i = 0; i < n; i++) {
    var r = readline()
      .split(" ")
      .map((val, ind) => {
        val = parseInt(val);
        if (val == 1) {
          rows[i] = 0;
          col[ind] = 0;
          return val;
        }
      });
  }
  var count1 = 0;
  for (var i = 0; i < n; i++) {
    if (rows[i] == 1) count1++;
  }
  var count2 = 0;
  for (var i = 0; i < n; i++) {
    if (col[i] == 1) count2++;
  }
  var myCount = Math.min(count1, count2);
  if (myCount % 2 == 0) print("Vivek");
  else print("Ashish");
}

// const bg = require('big-integer')
process.stdin.resume()
process.stdin.setEncoding('utf-8')
const MOD1 = 1000000007

function alpha(c = 'A') {
  return [...{
    _b: c === 'A' ? 65 : 97,
    _i: -1,
    [Symbol.iterator]() {
      return this
    },
    next() {
      this._i++
      if (this._i === 26) return {done: true}
      else return {done: false, value: String.fromCharCode(this._i + this._b)}
    }
  }]
}

class rc {
  static construct() {
    this.input = ''
    this.ptr = 0
  }
  static readString() {
    return this.input[this.ptr++]
  }

  static readStrings() {
    return this.input[this.ptr++].split(' ')
  }

  static readInt() {
    return +this.readString()
  }

  static readInts() {
    return this.readStrings().map(a => +a)
  }

  static readBigInteger() {
    return bg(this.readString())
  }

  static readBigIntegers() {
    return this.readStrings().map(a => bg(a))
  }
}

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

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

rc.construct()
// bc.construct()
process.stdin.on('data', (i) => {
  rc.input += i
})

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

function main() {
  let t = rc.readInt()
  while (t--) {
    const [n, m] = rc.readInts()
    const a = new Array(n)
    let count = 0
    for(let i = 0; i < n; i++) {
      a[i] = rc.readInts()
      let x = a[i].includes(1)
      if(x) count++
    }

    let diff = n - count

    // wr(count)

    if((diff & 1) === 0) wr('Vivek')
    else wr('Ashish')
  }

}

//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
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;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var M = one[1];
		var list = new Array(N);
		var used = new Set();
		for(var j = 0; j < N; j++){
			list[j] = nextStrArray();
		}
		var turn = true;//true:Asish,false:Vivek
		while(true){
			if(turn){
				var isChange = false;
				for(var j = 0; j < N; j++){
					if(isChange){
						break;
					}
					for(var k = 0; k < M; k++){
						if(isChange){
							break;
						}
						if(list[j][k] == "0"){
							var isNG = false;
							for(var l = 0; l < N; l++){
								if(list[l][k] == "1"){
									isNG = true;
									break;
								}
							}
							for(var l = 0; l < M; l++){
								if(list[j][l] == "1"){
									isNG = true;
									break;
								}
							}
							if(!isNG){
								list[j][k] = "1";
								isChange = true;
							}
						}
					}
				}
				if(isChange){
					turn = false;
				}else{
					break;
				}
			}else{
				var isChange = false;
				for(var j = 0; j < N; j++){
					if(isChange){
						break;
					}
					for(var k = 0; k < M; k++){
						if(isChange){
							break;
						}
						if(list[j][k] == "0"){
							var isNG = false;
							for(var l = 0; l < N; l++){
								if(list[l][k] == "1"){
									isNG = true;
									break;
								}
							}
							for(var l = 0; l < M; l++){
								if(list[j][l] == "1"){
									isNG = true;
									break;
								}
							}
							if(!isNG){
								list[j][k] = "1";
								isChange = true;
							}
						}
					}
				}
				if(isChange){
					turn = true;
				}else{
					break;
				}
			}
		}
		if(turn){
			output[i] = "Vivek";
		}else{
			output[i] = "Asish";
		}
	}
	myout(myconv(output,9));
}

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

var N = null,
    init = true,
    n = 0,
    m = 0,
    r, u, w

function initMatrix(line) {
    const size = line.split(" ").map(x => parseInt(x,10))
    u = new Set()
    w = new Set()
    n = size[0]
    m = size[1]
    r = 0
    init = false
}

function inputRow(line) {
    for (let c=0;c<2*m;c=c+2) {
        if (line[c] == "1") {
            u.add(r)
            w.add(c)
        }
    }
    if (++r == n) {
        n -= u.size
        m -= w.size
        console.log(n == 1 || m == 1 || (n-n%m)%2 == 1 ? "Ashish":"Vivek")
        init = --N == 0 ? rl.close() : true
    }
}

function loop(line) {
    if (line.trim() == "") return
    (init ? initMatrix : inputRow)(line)
}

rl.question("", line => {
    N = parseInt(line,10)
    rl.on("line", loop)
})

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

var N = null,
    init = true,
    n = 0,
    m = 0,
    r, u, w

function initMatrix(line) {
    const size = line.split(" ").map(x => parseInt(x,10))
    u = new Set()
    w = new Set()
    n = size[0]
    m = size[1]
    r = 0
    init = false
}

function inputRow(line) {
    for (let c=0;c<2*m;c=c+2) {
        if (line[c] == "1") {
            u.add(r)
            w.add(c)
        }
    }
    if (++r == n) {
        n -= u.size
        m -= w.size
        console.log(n != 0 && m != 0 && (n == 1 || m == 1 || (n-n%m)%2 == 1) ? "Ashish":"Vivek")
        init = --N == 0 ? rl.close() : true
    }
}

function loop(line) {
    if (line.trim() == "") return
    (init ? initMatrix : inputRow)(line)
}

rl.question("", line => {
    N = parseInt(line,10)
    rl.on("line", loop)
})


const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const m = Array(n).fill(0)
        .map(() => [])
    for (let i = 0; i < arr.length; i++) {
        const x = arr[i]
        const y = i + x
        // m[y] = m[y] || []
        if (i + x < n) {
            m[y].push(x)
        }
    }
    const dp = Array(n).fill(0)
    if (arr[0] < n) dp[arr[0]] = 1
// console.log(m)
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] === i) {
            dp[i] = 1
            continue
        }
        // dp[i] |= dp[i - arr[i]] || 0
        dp[i] |= dp[i - arr[i] - 1] || 0
        for (let j = 0; j < m[i].length; j++) {
            // dp[i] |= dp[m[i][j]] || 0
            dp[i] |= dp[i - m[i][j] - 1] || 0
            // console.log(i, dp[i - m[i][j] - 1], i - m[i][j] - 1)
        }
    }
// console.log(dp)
    return dp[n - 1] ? 'YES' : 'NO'
}

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}

var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
	var n = readline();
	var a = readline().split(" ").map(w => parseInt(w));
	var dp = [];
	for(var i=0;i<=n;i++) dp[i] = 0;
	dp[0] = 1;
	for(var i=1;i<=n;i++) {
		if(i-a[i-1] > -1 && dp[i-a[i-1]-1]) dp[i] = 1;
		if(i+a[i-1] <= n && dp[i-1]) dp[i+a[i-1]] = 1;
	}
	console.log(dp[n] ? "Yes" : "No")
}

'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 = [];
  for (let i = 0; i < n; i++) {
    a[i + 1] = rn();
  }
  const dp = new Array(n + 1).fill(false);
  dp[0] = true;
  for (let i = 1; i <= n; i++) {
    dp[i] = dp[i] || !!dp[i - a[i] - 1];
    if (dp[i - 1] && i + a[i] <= n) dp[i + a[i]] = true;
  }
  if (dp[n]) return 'YES';
  return 'NO';
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    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(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const m = Array(n).fill(0)
        .map(() => [])
    for (let i = 0; i < arr.length; i++) {
        const x = arr[i]
        const y = i + x
        // m[y] = m[y] || []
        if (i + x < n) {
            m[y].push(x)
        }
    }
    const dp = Array(n).fill(0)
    if (arr[0] < n) dp[arr[0]] = 1
// console.log(m)
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] === i) {
            dp[i] = 1
            continue
        }
        dp[i] |= dp[i - arr[i]] || 0
        for (let j = 0; j < m[i].length; j++) {
            dp[i] |= dp[m[i][j]]
        }
    }
// console.log(dp)
    return dp[n - 1] ? 'YES' : 'NO'
}


var dn = readline().split(" ").map(e=>+e);var n =dn[1];var f = Number(readline());

for(var i=0;i<f;i++){
var t = readline().split(" ").map(e=>+e)
var y1 = Math.abs(t[0]-n);
var y2 = t[0]+n;
if(y2>dn[0]){y2= dn[0] - (y2-dn[0])}

if((t[1]<y1)||(t[1]>y2)){print("NO");}else{print("YES");}
}

var input = readline().split(" ").map(function(el) {return parseInt(el)});
var n = input[0];
var d = input[1];
var m = parseInt(readline());
for (var i = 0; i < m; i++) {
    var point = readline().split(" ").map(function(el) {return parseInt(el)});
    var x = point[0];
    var y = point[1];
    if (y <= x + d && y <= (x*(-1)+2*n-d) && y >= x-d && y >= d-x)
        print("YES");
    else
        print("NO");
}

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

var n = Number(input[0]);
var d = Number(input[1]);

var points = [];
points.push([d,0]);
points.push([n, Math.abs(n-d)]);
points.push([Math.abs(n-d), n]);
points.push([0,d]);

var b = FindLength(points[0][0], points[1][0], points[0][1], points[1][1]);
var l = FindLength(points[1][0], points[2][0], points[1][1], points[2][1]);

var RectArea = Math.round(b*l);

function FindLength(x1, x2, y1, y2) {
  return Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

function FindTriArea(p1, p2, p3) {
  return Math.abs(((p1[0]-p3[0])*(p2[1]-p1[1]) - (p1[0]-p2[0])*(p3[1]-p1[1]))/2);
}

var m = Number(readline());

for(var i=0; i<m; i++) {
  var gp = (readline().split(' ')).map(function(x){ return Number(x);});
  var TriArea = FindTriArea(points[0], gp, points[1])+
                FindTriArea(points[1], gp, points[2])+
                FindTriArea(points[2], gp, points[3])+
                FindTriArea(points[3], gp, points[0]);

  if(parseFloat(RectArea.toFixed(7)) == parseFloat(TriArea.toFixed(7))) {
    print("YES");
  }
  else {
    print("NO");
  }
}