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

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = new Map();
var b = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.set(index, (a.get(index) || 0) + 1);
});

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    b.set(index, (b.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue, index) {
    if (currentValue !== b.get(index)) {
        ans.push(index);

        if (currentValue == 1) {
            a.delete(index);
        } else {
            a.set(index, currentValue - 1);
        }
    }
});

b = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    b.set(index, (b.get(index) || 0) + 1);
});

a.forEach(function(currentValue, index) {
    if (currentValue !== b.get(index)) {
        ans.push(index);

        if (currentValue == 1) {
            a.delete(index);
        } else {
            a.set(index, currentValue - 1);
        }
    }
});

write(ans.join('\n'));

readline();

var a = readNums();
var b = readNums();
print(diff(a, b));
a = b;
b = readNums();
print(diff(a, b));

function diff(a, b) {
    var d = {};
    a.map(v => d[v] = (d[v] || 0) + 1);
    b.map(v => d[v] = (d[v] || 0) - 1);
    for (var k in d) {
        if (d[k])
            return k;
    }
}

function readNums() {
    return readline().split(' ').map(v => v - 0)
}

var n = parseInt(readline().trim())
var a = readline().trim().split(' ').map((x)=>parseInt(x))
var b = readline().trim().split(' ').map((x)=>parseInt(x))
var c = readline().trim().split(' ').map((x)=>parseInt(x))

var _sort=(_a,_b)=>_a-_b;
a.sort(_sort)
b.sort(_sort)
c.sort(_sort)

var _b=-1;
for(var i=0;i<n-1;i++){
    if(a[i]!=b[i]){
        _b=a[i];
        break;
    }
}
if(_b==-1)
    _b=a[n-1];

var _c=-1;
for(var i=0;i<n-2;i++){
    if(c[i]!=b[i]){
        _c=b[i];
        break;
    }
}
if(_c==-1)
    _c=b[n-2];

print(_b);
print(_c);

var n = parseInt(readline().trim())
var a = readline().trim().split(' ').map((x)=>parseInt(x))
var b = readline().trim().split(' ').map((x)=>parseInt(x))
var c = readline().trim().split(' ').map((x)=>parseInt(x))

var _a={}, _b={}, _c={}
for(var i=0;i<n;i++){
    if(_a[a[i]]==undefined)
        _a[a[i]]=0
    _a[a[i]]++
}
for(var i=0;i<n-1;i++){
    if(_b[b[i]]==undefined)
        _b[b[i]]=0
    _b[b[i]]++
}
for(var i=0;i<n-2;i++){
    if(_c[c[i]]==undefined)
        _c[c[i]]=0
    _c[c[i]]++
}

//print(JSON.stringify(_a),JSON.stringify(_b),JSON.stringify(_c))
for(var i in _a){
   // print(i,_b[i],_a[i])
    if(_b[i]!=_a[i]){
        print(i);
        break;
    }
}

for(var i in _b){
    if(_b[i]!=_c[i]){
        print(i);
        break;
    }
}

(function () {
	'use strict';

	var n = parseInt(readline()),
		a = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),
		b = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),
		c = readline().split(' ').map(Number).sort(function (a, b) { return a - b; });

	print((function () {
		for (var i = 0, _i = b.length; i < _i; i++)
			if (a[i] !== b[i]) return a[i];
		return a.pop();
	})());

	print((function () {
		for (var i = 0, _i = c.length; i < _i; i++)
			if (b[i] !== c[i]) return b[i];
		return b.pop();
	})());

}).call(this);

readline()
A=readline().split(' ').map(Number)
AA=new Array(A.length)
for (var i of A)
    AA[i] = (AA[i]||0)+1

readline().split(' ').map(Number).forEach(c=>AA[c]--);

var f;
for (var i in AA)
    if (AA[i]) f=i;

AA=new Array(A.length)
for (var i of A)
    AA[i] = (AA[i]||0)+1

readline().split(' ').map(Number).forEach(c=>AA[c]--);
AA[f]--;
var ff;
for (var i in AA) {
    if (AA[i]) ff=i;
}

print(f)
print(ff)

function main(a, b, c) {
    var output = '';
    var aValues = sum(a);
    var bValues = sum(b);
    var cValues = sum(c);

    output += aValues - bValues + '\n';
    output += bValues - cValues;

    return output;
}

function sum(array) {
    var sumResult = 0;
    for (var i = array.length; i--;) {
        sumResult += array[i];
    }

    return sumResult;
}

var n = readline();
var input = [];
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));

print(main(input[0], input[1], input[2]));

function main(a, b, c) {
    var output = '';
    var aValues = a.reduce(function(x, y) { return x + y }, 0);
    var bValues = b.reduce(function(x, y) { return x + y }, 0);
    var cValues = c.reduce(function(x, y) { return x + y }, 0);

    output += aValues - bValues + '\n';
    output += bValues - cValues;

    return output;
}

var n = readline();
var input = [];
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));

print(main(input[0], input[1], input[2]));

str = Number(readline());
first = readline().split(' ').map(Number);
second = readline().split(' ').map(Number);
third = readline().split(' ').map(Number);

first.sort();
second.sort();
third.sort();

for (var i = 0, j = 0, k = 0; i < first.length; i++) {
    if (first[i] == second[j] && first[i] == third[k]) {j++; k++;}
    else if ((first[i] == second[j]) && (first[i] != third[k])) {si = first[i]; j++;}
    else if ((first[i] != second[j]) && (first[i] != third[k])) {fi = first[i];}

}

write(fi + '\n' + si);

function main(a, b, c) {
    var output = '';
    var aValues = cacheValues(a);
    var bValues = cacheValues(b);
    var cValues = cacheValues(c);

    output += compare(aValues, bValues) + '\n';
    output += compare(bValues, cValues);

    return output;
}

function cacheValues(values) {
    var cachedValues = [];

    for(var i = 0; i < values.length; i++) {
        if (!cachedValues[`n${values[i]}`]) {
            cachedValues[`n${values[i]}`] = 1;
        } else {
            cachedValues[`n${values[i]}`]++;
        }
    }

    return cachedValues;
}

function compare(a, b) {
    var differ = 0;

    for (key in a) {
        if(a[key] !== b[key]) {
            differ = parseInt(key.slice(1));
            break;
        }
    }

    return differ;
}

var n = readline();
var input = [];
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));

print(main(input[0], input[1], input[2]));

function sum(array){			//суммирование массива
	var result = 0;
	for(var i = 0; i < array.length; i++){
		result += +array[i];
	}
	return result;
}

var n = +readline(), a = sum(readline().split(" ")), b = sum(readline().split(" ")), c = sum(readline().split(" "));

write((a-b) + "\n" + (b-c));

function sum(array) {
    var sumResult = 0;
    for (var i = array.length; i--;) {
        sumResult += +array[i];
    }

    return sumResult;
}

var n = readline();
a = readline().split(' ');
b = readline().split(' ');
c = readline().split(' ');

var bValues = sum(b);
print((sum(a) - bValues) + '\n' + (bValues - sum(c)));

Array.prototype.toMap = function toMap()    {
    var resultMap = {};
    this.forEach(function(value, index) {
        if(resultMap[value])    {
            resultMap[value] += 1;
        } else    {
            resultMap[value] = 1;
        }
    });
    return resultMap;
};

function main()  {
    var errorCount = readline(),
        fstErrorList = readline().split(/\s/).map(Number),
        fstErrorMap = fstErrorList.toMap(),
        sndErrorList = readline().split(/\s/).map(Number),
        sndErrorMap = sndErrorList.toMap(),
        trdErrorMap = readline().split(/\s/).map(Number).toMap(),
        result = [];

    // console.log('%o, %o, %o', fstErrorMap, sndErrorMap, trdErrorMap);

    fstErrorList.some(function(errorLine)    {
        if(fstErrorMap[errorLine] != sndErrorMap[errorLine])    {
            result.push(errorLine);
            return true;
        }
    });

    sndErrorList.some(function(errorLine)    {
        if(sndErrorMap[errorLine] != trdErrorMap[errorLine])    {
            result.push(errorLine);
            return true;
        }
    });

    print(result.join('\n'));
};

main();

function sum(array) {
    var sumResult = 0;

    var i = 0;
    var l = array.length;
    for (i = l; i--;) {
        sumResult += +array[i];
    }

    return sumResult;
}

readline();
var aValues = sum(readline().split(' '));
var bValues = sum(readline().split(' '));
print((aValues - bValues) + '\n' + (bValues - sum(readline().split(' '))));

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline().split(' ').map(x => parseInt(x));
var thirdErrors = readline().split(' ').map(x => parseInt(x));
firstErrors.sort((a,b) => a-b);
secondErrors.sort((a,b) => a-b);
thirdErrors.sort((a,b) => a-b);
var errors = [];
var somethingChanged = false;
for (var i = 0; i < limit - 1; i++) {
  if (secondErrors[i] !== firstErrors[i]) {
    errors.push(firstErrors[i]);
    somethingChanged = true;
    break;
  }
}
if (!somethingChanged) errors.push(firstErrors[limit-1]);
somethingChanged = false;
for (var j = 0; j < limit - 2; j++) {
  if (thirdErrors[j] !== secondErrors[j]) {
    errors.push(secondErrors[j])
    somethingChanged = true;
    break;
  }
}
if (!somethingChanged) errors.push(secondErrors[limit-2]);
for (var k = 0; k < errors.length; k++) print(errors[k]);

var n=Number(readline());
var arr=readline().split(" ");
arr.sort();
var arr1=readline().split(" ");
arr1.sort();
var flag1=false;
for(var i=0;i<n-1;i++){
	if(arr1[i]!=arr[i]){
		flag1=true;
		print(arr[i]);
		break;
	}
}
if(!flag1){
	print(arr[n-1]);
}
var arr2=readline().split(" ");
arr2.sort();
var flag2=false;
for(var i=0;i<n-2;i++){
	if(arr2[i]!=arr1[i]){
		flag2=true;
		print(arr1[i]);
		break;
	}
}
if(!flag2){
	print(arr1[n-2]);
}

var n = readline();
var str1 = readline().split(" ").reduce((x,y)=>(Number(x)+Number(y)));
var str2 = readline().split(" ").reduce((x,y)=>(Number(x)+Number(y)));
var str3 = readline().split(" ").reduce((x,y)=>(Number(x)+Number(y)));

print(str1-str2);
print(str2-str3);

var nums = readNums();

var arr1 = readNums();
var arr2 = readNums();
var arr3 = readNums();

arr1.sort(function(a,b){return b-a});
arr2.sort(function(a,b){return b-a});
arr3.sort(function(a,b){return b-a});

var k = 0;

for (var i = 0; i <arr2.length; i++) {
    if (arr1[i] > arr2[i]) {
        print(arr1[i]);
        k = 1;
        break;
    }
}

if (k == 0 && arr1[arr1.length-1] <= arr2[arr2.length-1]) {
    print(arr1[arr1.length-1]);
}

var l = 0;

for (var i = 0; i <arr3.length; i++) {
    if (arr2[i] > arr3[i]) {
        print(arr2[i]);
        l = 1;
        break;
    }
}

if (l == 0 && arr2[arr2.length-1] <= arr3[arr3.length-1]) {
    print(arr2[arr2.length-1]);
}

function readNums() {
    return readline().split(' ').map(function(v) {
        return v - 0;
    })
}

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var n = rdN();
    var A = rdArN().sortLt();
    var B = rdArN().sortLt();
    var C = rdArN().sortLt();
    for (var i = 0; i < A.length; ++i) {
        if (A[i] !== B[i]) {
            pr(A[i]);
            break;
        }
    }
    for (var i = 0; i < B.length; ++i) {
        if (B[i] !== C[i]) {
            pr(B[i]);
            break;
        }
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const rdS=readline;
const rdN=()=>+rdS();
const rdArS=()=>rdS().split(' ');
const rdArN=()=>rdArS().map(v=>+v);
const wr=write;
const pr=print;
const prAr=(a)=>pr(...a);
const prOb=(o)=>pr(JSON.stringify(o,null,4));
const cmpLt=(a,b)=>a-b;
const cmpGt=(a,b)=>b-a;
const crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};
const getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}var primes=[];for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;};
const defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});
defineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});
defineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});
defineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});
defineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});

main();
return OUTPUT;
})();

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var n = rdN();
    var A = rdArN().sortLt();
    var B = rdArN().sortLt().concat([null]);
    var C = rdArN().sortLt().concat([null, null]);
    for (var i = 0; i < A.length; ++i) {
        if (A[i] !== B[i]) {
            pr(A[i]);
            break;
        }
    }
    for (var i = 0; i < B.length; ++i) {
        if (B[i] !== C[i]) {
            pr(B[i]);
            break;
        }
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const rdS=readline;
const rdN=()=>+rdS();
const rdArS=()=>rdS().split(' ');
const rdArN=()=>rdArS().map(v=>+v);
const wr=write;
const pr=print;
const prAr=(a)=>pr(...a);
const prOb=(o)=>pr(JSON.stringify(o,null,4));
const cmpLt=(a,b)=>a-b;
const cmpGt=(a,b)=>b-a;
const crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};
const getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}var primes=[];for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;};
const defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});
defineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});
defineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});
defineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});
defineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});

main();
return OUTPUT;
})();

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

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

readLine.on('close', () => {
  const set = new Set();

  const f1 = input[1].split(' ').map(x => parseInt(x));
  const f2 = input[2].split(' ').map(x => parseInt(x));
  const f3 = input[3].split(' ').map(x => parseInt(x));

  f1.sort((a, b) => a - b);
  f2.sort((a, b) => a - b);
  f3.sort((a, b) => a - b);

  const answ = [];
  for (let i = 0; i < f1.length; i += 1) {
    if (f1[i] !== f2[i]) {
      answ.push(f1[i]); break;
    }
    if (i + 1 === f2.length) { answ.push(f1.pop()); break; }
  }

  for (let i = 0; i < f2.length; i += 1) {
    if (f2[i] !== f3[i]) {
      answ.push(f2[i]); break;
    }

    if (i + 1 === f3.length) { answ.push(f2.pop()); break; }
  }

  answ.forEach(x => console.log(x));
});

var readline = (function () {
    var lines = require("fs")
        .readFileSync(0, "utf-8")
        .split("\n");
    var i = 0;
    return function () { return lines[i++]; };
})();
var initialErrors = parseInt(readline());
var first = readline()
    .split(" ")
    .map(function (v) { return parseInt(v); })
    .sort();
var second = readline()
    .split(" ")
    .map(function (v) { return parseInt(v); })
    .sort();
var third = readline()
    .split(" ")
    .map(function (v) { return parseInt(v); })
    .sort();
var hasFirst = false;
var hasSecond = false;
var firstError = 0;
var secondError = 0;
for (var i = 0; i < initialErrors && !(hasFirst && hasSecond); i++) {
    if (!hasFirst) {
        if (first[i] !== second[i]) {
            hasFirst = true;
            firstError = first[i];
        }
    }
    if (!hasSecond) {
        if (second[i] !== third[i]) {
            hasSecond = true;
            secondError = second[i];
        }
    }
}
console.log(firstError);
console.log(secondError);

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

let stdin = '';

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

process.stdin.on('end', () => {
  const data = stdin.split('\n');
  data.shift();

  const sum = [0, 0, 0];

  data.forEach((errors, i) => {
    errors.split(' ').forEach((value) => {
      sum[i] += Number(value);
    });
  });

  process.stdout.write(`${sum[0] - sum[1]}\n${sum[1] - sum[2]}`);
});

readline()
A=readline().split(' ').map(Number).reduce((a,c)=>{ a[c]=(a[c]||0)+1; return a; },{});
B=Object.assign({},A)
readline().split(' ').map(Number).forEach(c=>A[c]--);
var f;
for (i of Object.keys(A))
    if (A[i]) f=i;

readline().split(' ').map(Number).forEach(c=>B[c]--);
B[f]--;
var ff;
for (i of Object.keys(B))
    if (B[i]) ff=i;

print(f)
print(ff)
//print(JSON.stringify(A))
//print(JSON.stringify(B))

str = Number(readline());
first = readline().split(' ').map(Number);
second = readline().split(' ').map(Number);
third = readline().split(' ').map(Number);
first.sort();
third.sort();
var si = 0, fi = 0;
for (var i = 0, j = 0; i < first.length; i++)
    if (third[j] === first[i]) {j++}
    else {
        if (second.indexOf(first[i]) >= 0) si = first[i];
        else fi = first[i];
    }
write(fi + '\n' + si);

str = Number(readline());
first = readline().split(' ').map(Number);
second = readline().split(' ').map(Number);
third = readline().split(' ').map(Number);
first.sort(function(a,b) {return a - b});
third.sort(function(a,b) {return a - b});
var si = 0, fi = 0;
for (var i = 0, j = 0; i < first.length; i++)
    if (third[j] === first[i]) {j++}
    else {
        if (second.indexOf(first[i]) >= 0) si = first[i];
        else fi = first[i];
    }
write(fi + '\n' + si);

str = Number(readline());
first = readline().split(' ').map(Number);
second = readline().split(' ').map(Number);
third = readline().split(' ').map(Number);
var mem1 = [], mem2 = [];
var si = [], fi = [];
for (var i = 0; i < first.length; i++) {
    mem1[first[i]] = mem1[first[i]] + 1 || 1;
}

for (var i = 0; i < second.length; i++) {
    mem1[second[i]]--;
    mem2[second[i]] = mem2[second[i]] + 1 || 1;
}

for (var i = 0; i < third.length; i++) {
    mem2[third[i]]--;
}

for (var i = 0; i < mem1.length; i++) {
    if (mem1[i] !== 0) fi = i;
    if (mem2[i] !== 0) si = i;
}

write(fi + '\n' + si);

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

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = [];
var b = new Map();
var c = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.push(index);
    b.set(index, (b.get(index) || 0) + 1);
});

readline();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    c.set(index, (c.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue, index) {
    if (b.get(index) !== c.get(index)) {
        ans.push(index);
    }
});

write(ans.join('\n'));

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

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = new Map();
var b = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.set(index, (a.get(index) || 0) + 1);
});

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    b.set(index, (b.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue, index) {
    if (currentValue !== b.get(index)) {
        ans.push(index);
        a.delete(index);
    }
});

b = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    b.set(index, (b.get(index) || 0) + 1);
});

a.forEach(function(currentValue, index) {
    if (currentValue !== b.get(index)) {
        ans.push(index);
        a.delete(index);
    }
});

write(ans.join('\n'));

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

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = [];
var b = new Map();
var c = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.push(currentValue);
    b.set(index, (b.get(index) || 0) + 1);
});

readline();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    c.set(index, (c.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue, index) {
    if (b.get(index) !== c.get(index)) {
        ans.push(index);
    }
});

write(ans.join('\n'));

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

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = [];
var b = new Map();
var c = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.push(index);
    b.set(index, (b.get(index) || 0) + 1);
});

readline();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    c.set(index, (c.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue) {
    if (b.get(currentValue) !== c.get(currentValue)) {
        ans.push(currentValue);

        b.delete(currentValue);
        c.delete(currentValue);
    }
});

write(ans.join('\n'));

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

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = new Map();
var b = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.set(index, (a.get(index) || 0) + 1);
});

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    b.set(index, (b.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue, index) {
    if (b.get(index) !== currentValue) {
        ans.push(index);
    }
});

b = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    b.set(index, (b.get(index) || 0) + 1);
});

a.forEach(function(currentValue, index) {
    if (ans[0] !== currentValue && b.get(index) !== currentValue) {
        ans.push(index);
    }
});

write(ans.join('\n'));

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

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = new Map();
var c = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.set(index, (a.get(index) || 0) + 1);
});

readline();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    c.set(index, (c.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue, index) {
    if (c.get(index) !== a.get(index)) {
        ans.push(index);
    }
});

write(ans.join('\n'));

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
var mapCopy = new Map(map);
for (var j = 0; j < limit - 2; j++) {
  map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next();
  if ((map.get(key) === mapCopy.get(key)) || ((map.get(key) !== mapCopy.get(key)) && mapCopy.get(key) !== 0)) {
    var n = map.get(key) - mapCopy.get(key);
    n = n === 0 ? 1 : n;
    while (n) {
      n--
      errors.push(key);
    }
  }
}
for (var e = 0; e < errors.length; e++) print(errors[e]);

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
var mapCopy = new Map(map);
for (var j = 0; j < limit - 2; j++) {
  mapCopy.set(thirdErrors[j], mapCopy.get(thirdErrors[j]) - 1);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next().value;
  if ((map.get(key) === mapCopy.get(key)) || ((map.get(key) !== mapCopy.get(key)) && mapCopy.get(key) !== 0)) {
    var n = map.get(key) - mapCopy.get(key);
    n = n === 0 ? 1 : n;
    while (n) {
      n--
      errors.push(key);
    }
  }
}
for (var e = 0; e < errors.length; e++) print(errors[e]);

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
for (var j = 0; j < limit - 2; j++) {
  map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);
  if (map.get(thirdErrors[j]) === 0) map.delete(thirdErrors[j]);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next().value;
  print(key);
}

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
for (var j = 0; j < limit - 2; j++) {
  map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);
  if (map.get(thirdErrors[j]) === 0) map.delete(thirdErrors[j]);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next().value;
  if (limit === 10) print(keys);
  print(key);
}

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
for (var j = 0; j < limit - 2; j++) {
  map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);
  if (map.get(thirdErrors[j]) === 0) map.delete(thirdErrors[j]);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next().value;
  if (limit === 10) print([...keys]);
  print(key);
}

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
var mapCopy = new Map(map);
for (var j = 0; j < limit - 2; j++) {
  map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next();
  print(key);
  if ((map.get(key) === mapCopy.get(key)) || ((map.get(key) !== mapCopy.get(key)) && mapCopy.get(key) !== 0)) {
    var n = map.get(key) - mapCopy.get(key);
    n = n === 0 ? 1 : n;
    while (n) {
      n--
      errors.push(key);
    }
  }
}
for (var e = 0; e < errors.length; e++) print(errors[e]);

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
var mapCopy = new Map(map);
for (var j = 0; j < limit - 2; j++) {
  mapCopy.set(thirdErrors[j], mapCopy.get(thirdErrors[j]) - 1);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next().value;
  if ((map.get(key) === mapCopy.get(key)) || ((map.get(key) !== mapCopy.get(key)) && mapCopy.get(key) !== 0)) {
    var n = map.get(key) - mapCopy.get(key);
    n = n === 0 ? 1 : n;
    while (n) {
      n--
      if (errors.length && errors[0] > key) {
        errors[1] = errors[0];
        errors[0] = key;
      } else errors.push(key);
    }
  }
}
for (var e = 0; e < errors.length; e++) print(errors[e]);

var n = +readline(), a = readline().split(" ");
readline();
var c = readline().split(" "), k = [];

a.forEach(function(error, i){
	var index = c.indexOf(error);
	if(index + 1){
		delete c[index];
	}
	else{
		k.push(i);
	}
});

write(a[k[0]] + "\n" + a[k[1]]);

var n = +readline(), a = readline().split(" ");
readline();
var c = readline().split(" "), k = [];

a.forEach(function(error, i){
	var index = c.indexOf(error);
	if(index + 1){
		delete c[index];
	}
	else{
		k.push(i);
	}
});

write( (a[k[0]] > a[k[1]]) ? (a[k[1]] + "\n" + a[k[0]]) : (a[k[0]] + "\n" + a[k[1]]) );

(function () {
	'use strict';

	var n = parseInt(readline()),
		a = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),
		b = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),
		c = readline().split(' ').map(Number).sort(function (a, b) { return a - b; });

	print((function () {
		for (var i = 0, _i = b.length; i < _i; i++)
			if (a[i] !== b[i]) return a[i];
		return a.pop()[0];
	})());

	print((function () {
		for (var i = 0, _i = c.length; i < _i; i++)
			if (b[i] !== c[i]) return b[i];
		return b.pop()[0];
	})());

}).call(this);

(function () {
	'use strict';

	var n = parseInt(readline()),
		a = readline().split(' '),
		b = readline().split(' '),
		c = readline().split(' ');

	print((function () {
		for (var i = 0; i < a.length; i++)
			if (b.indexOf(a[i]) === -1)
				return a[i];
	})());

	print((function () {
		for (var i = 0; i < b.length; i++)
			if (c.indexOf(b[i]) === -1)
				return b[i];
	})());

}).call(this);

function sum(array) {
    var sumResult = 0;

    var i = 0;
    var l = array.length;
    for (i = l; i--;) {
        sumResult += +array[i];
    }

    return sumResult;
}

readline();
var bValues = sum(readline().split(' '));
print((sum(readline().split(' ')) - bValues) + '\n' + (bValues - sum(readline().split(' '))));

var nums = readNums();

var arr1 = readNums();
var arr2 = readNums();
var arr3 = readNums();

arr1.sort(function(a,b){return b-a});
arr2.sort(function(a,b){return b-a});
arr3.sort(function(a,b){return b-a});

for (var i = 0; i <arr2.length; i++) {
    if (arr1[i] > arr2[i]) {
        print(arr1[i]);
        break;
    }
}

if (arr1[arr1.length-1] <= arr2[arr2.length-1]) {
    print(arr1[arr1.length-1]);
}

for (var i = 0; i <arr3.length; i++) {
    if (arr2[i] > arr3[i]) {
        print(arr2[i]);
        break;
    }
}

if (arr2[arr2.length-1] <= arr3[arr3.length-1]) {
    print(arr2[arr2.length-1]);
}

function readNums() {
    return readline().split(' ').map(function(v) {
        return v - 0;
    })
}

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    rdN();
    var A = rdArN();
    var B = rdArN();
    var C = rdArN();
    var ABC = [...A, ...B, ...C];
    var M = {};
    for (var i = 0; i < ABC.length; ++i) {
        var value = ABC[i];
        M[value] = ++M[value] || 1;
    }
    for (var key in M) {
        var count = M[key];
        if (count%3 === 1) {
            pr(key);
        }
    }
    for (var key in M) {
        var count = M[key];
        if (count%3 === 2) {
            pr(key);
        }
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const rdS=readline;
const rdN=()=>+rdS();
const rdArS=()=>rdS().split(' ');
const rdArN=()=>rdArS().map(v=>+v);
const wr=write;
const pr=print;
const prAr=(a)=>pr(...a);
const prOb=(o)=>pr(JSON.stringify(o,null,4));
const cmpLt=(a,b)=>a-b;
const cmpGt=(a,b)=>b-a;
const crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};
const getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}var primes=[];for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;};
const defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});
defineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});
defineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});
defineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});
defineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});

main();
return OUTPUT;
})();


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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var n = integers[0], m = integers[1], k = integers[2];

	var maze = [], distances = [];
	var startR = -1, startC = -1;
	var inf = n*m;
	for (var r = 0; r < n; r += 1) {
		maze.push(readline());
		distances.push([]);
		for (var c = 0; c < m; c += 1) {
			distances[r].push(inf);
			if (maze[r][c] == '.') {
				startR = r;
				startC = c;
			}
		}
	}

	distances[startR][startC] = 0;
	var queue = [{r: startR, c: startC}];
	var dr = [-1, 0, 1, 0], dc = [0, 1, 0, -1];
	while (queue.length != 0) {
		var r = queue[0].r, c = queue[0].c;
		queue = queue.slice(1);
		var distance = distances[r][c] + 1;
		for (var i = 0; i < 4; i += 1) {
			var nextR = r + dr[i], nextC = c + dc[i];
			if (nextR >= 0 && nextR < n && nextC >= 0 && nextC < m &&
					maze[nextR][nextC] == '.' &&
					distance < distances[nextR][nextC]) {
				distances[nextR][nextC] = distance;
				queue.push({r: nextR, c: nextC});
			}
		}
	}

	var records = [];
	for (var r = 0; r < n; r += 1) {
		for (var c = 0; c < m; c += 1) {
			if (distances[r][c] < inf) {
				records.push({distance: distances[r][c], r: r, c: c});
			}
		}
	}
	records.sort(function(a, b) {
		return b.distance - a.distance;
	});

	for (var i = 0; i < k; i += 1) {
		var r = records[i].r, c = records[i].c;
		var line = maze[r];
		maze[r] = line.slice(0, c) + 'X' + line.slice(c+1);
	}

	for (var r = 0; r < n; r += 1) {
		print(maze[r]);
	}
}

main();

var input = readline().split(' ');
    var INF = 1000000000;
    var n=parseInt(input[0]),
        m=parseInt(input[1]),
        k=parseInt(input[2]);

    var labirinth = [], buf = [];
    for(var i=0; i<n; i++)
    {
        labirinth.push(readline().split('').map(function(e){return e=='#'?INF:0;}));
    }

    function bfs()
    {
        var startX=0, startY=0, result=[], queue = [];

        for(startY=0; startY<n && queue.length==0; startY++)
        {
            for(startX=0; startX<m && queue.length==0; startX++)
            {
                if(labirinth[startY][startX]==0)
                {
                    queue.push([startY,startX]);
                }
            }
        }

        var used = [];
        for(var i=0; i<n; i++)
        {
            used[i] = [];
            for(var j=0; j<m; j++) used[i][j]=0;
        }

        used[queue[0][0]][queue[0][1]]=1;

        function valid(y, x){return y>=0 && y<n && x>=0 && x<m && used[y][x]==0 && labirinth[y][x]!=INF;}
        while(queue.length)
        {
            var curr = queue.shift();
            used[curr[0]][curr[1]]=1;
            result.push(curr);
            if(valid(curr[0]+1,curr[1])) {
                queue.push([curr[0]+1,curr[1]]);
                used[curr[0]+1][curr[1]]=1;
            }
            if(valid(curr[0]-1,curr[1])) {
                queue.push([curr[0]-1,curr[1]]);
                used[curr[0]-1][curr[1]]=1;
            }
            if(valid(curr[0],curr[1]+1)) {
                queue.push([curr[0],curr[1]+1]);
                used[curr[0]][curr[1]+1]=1;
            }
            if(valid(curr[0],curr[1]-1)) {
                queue.push([curr[0],curr[1]-1]);
                used[curr[0]][curr[1]-1]=1;
            }
        }

        return result.reverse();
    }

    var order = bfs();
    for(var i=0; i<k; i++) labirinth[order[i][0]][order[i][1]]=-INF;
    for(var i=0; i<n; i++)
    {
        print(labirinth[i].map(function(e){return e==INF?'#':(e==-INF?'X':'.');}).join(''));
    }

var input = readline().split(' ');
    var INF = 1000000000;
    var n=parseInt(input[0]),
        m=parseInt(input[1]),
        k=parseInt(input[2]);

    var labirinth = [], buf = [];
    for(var i=0; i<n; i++)
    {
        labirinth.push(readline().split('').map(function(e){return e=='#'?INF:0;}));
    }

    function bfs()
    {
        var startX=0, startY=0, result=[], queue = [];

        for(startY=0; startY<n && queue.length==0; startY++)
        {
            for(startX=0; startX<m && queue.length==0; startX++)
            {
                if(labirinth[startY][startX]==0)
                {
                    queue.push([startY,startX]);
                }
            }
        }

        function valid(y, x){return y>=0 && y<n && x>=0 && x<m && labirinth[y][x]==0;}
        while(queue.length)
        {
            var curr = queue.shift();
            labirinth[curr[0]][curr[1]]=1;
            result.push(curr);
            if(valid(curr[0]+1,curr[1])) queue.push([curr[0]+1,curr[1]]);
            if(valid(curr[0]-1,curr[1])) queue.push([curr[0]-1,curr[1]]);
            if(valid(curr[0],curr[1]+1)) queue.push([curr[0],curr[1]+1]);
            if(valid(curr[0],curr[1]-1)) queue.push([curr[0],curr[1]-1]);
        }

        return result.reverse();
    }

    var order = bfs();
    for(var i=0; i<k; i++) labirinth[order[i][0]][order[i][1]]=-INF;
    for(var i=0; i<n; i++)
    {
        print(labirinth[i].map(function(e){return e==INF?'#':(e==-INF?'X':'.');}).join(''));
    }


'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

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

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

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = false;

class DSU {
  constructor(n){
    this.parents = new Array(n).fill(0);
    this.rank = new Array(n).fill(0);
    for (let i=0; i<n; i++)
      this.parents[i] = i;
  }
  getParent(x){
    if (this.parents[x]==x)
      return x;
    return this.parents[x] = this.getParent(this.parents[x]);
  }
  getRank(x){
    return this.rank[this.getParent(x)];
  }
  unite(x, y){
    x = this.getParent(x);
    y = this.getParent(y);
    if (x != y) {
      if (this.rank[x] < this.rank[y]){
        let tmp = x;
        x = y;
        y = tmp;
      }
      this.parents[y] = x;
      if (this.rank[x] == this.rank[y])
        this.rank[x]++;
    }
  }
}

const calc = (testN)=>{
  // READING:
  let [n, d] = ra();
  LT({n, d});
  let A = [];
  for (let i=0; i<d; i++){
    let [x, y] = ra();
    x--; y--;
    A.push([x, y]);
  }
  // PROCESSING:
  for (let I=0; I<d; I++){
    let dsu = new DSU(n);
    let extra = 0;
    for (let k=0; k<=I; k++){
      let px = dsu.getParent(A[k][0]);
      let py = dsu.getParent(A[k][1]);
      if (px==py){
        extra++
      } else {
        dsu.unite(px, py);
      }
    }
    let sets = [];
    let sizes = {};
    for (let i=0; i<n; i++){
      let p = dsu.getParent(i);
      if (sizes[p]){
        sizes[p]++;
      } else {
        sizes[p] = 1;
        sets.push(p);
      }
    }
    sets.sort((a, b)=>sizes[b]-sizes[a]);
    //L({I, extra, sets, sizes})
    let res = 0;
    for (let i=0; i<=extra && i<sets.length; i++){
      res += sizes[sets[i]];
    }
    print(res-1)
  }
};

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

class dsu {
	constructor (n) {
		this.components = n;
		this.data = Array(n).fill(-1);
	}
	unite (a, b) {
		// BEWARE: don't pass undefined values
		a = this.find(a);
		b = this.find(b);
		if (a == b) return;
		this.data[a] += this.data[b];
		this.data[b] = a;
		this.components--;
	}
	find (a) {
		return this.data[a] < 0 ? a : this.data[a] = this.find(this.data[a]);
	}
	size (a) {
		return -this.data[this.find(a)];
	}
	getcomponents () {
		return this.components;
	}
}

function main () {
	let [n, d] = rna();

	const a = new dsu(n);
	let extras = 0;
	while (d--) {
		let [x, y] = rna(); x--, y--;

		if (a.find(x) == a.find(y)) {
			extras++;
		} else {
			a.unite(x, y);
		}

		const sizes = [];
		for (let i = 0; i < n; i++) {
			if (a.find(i) == i) {
				sizes.push(a.size(i));
			}
		}
		sizes.sort((x, y) => y - x);

		let sum = 0;
		for (let i = 0; i < extras + 1; i++) {
			sum += sizes[i];
		}

		console.log(sum - 1);
	}
}

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

class dsu {
	constructor (n) {
		this.components = n;
		this.data = Array(n).fill(-1);
	}
	unite (a, b) {
		// BEWARE: don't past undefined values
		a = this.find(a);
		b = this.find(b);
		if (a == b) return;
		this.data[a] += this.data[b];
		this.data[b] = a;
		this.components--;
	}
	find (a) {
		return this.data[a] < 0 ? a : this.data[a] = this.find(this.data[a]);
	}
	size (a) {
		return -this.data[this.find(a)];
	}
	getcomponents () {
		return this.components;
	}
}

function main () {
	const [n, d] = rna();

	const a = new dsu(n);
	let extras = 0;
	for (let i = 0; i < d; i++) {
		let [x, y] = rna(); x--, y--;

		if (a.find(x) == a.find(y)) {
			extras++;
		} else {
			a.unite(x, y);
		}

		const sizes = [];
		for (let j = 0, visited = []; j < n; j++) {
			const cur = a.find(j);
			if (visited[cur]) continue;
			visited[cur] = 1;
			sizes.push(a.size(cur));
		}

		sizes.sort((x, y) => y - x);

		let sum = 0;
		for (let j = 0; j < extras + 1; j++) {
			sum += sizes[j];
		}

		console.log(sum- 1);
	}
}


"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++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
    let cnt = 0;
    if((n===3)&&(arr[1]%2===1)){
      console.log(-1);
      continue;
    }
    let ans = false;
    for(let i=1;i<n-1;i++){
      if(arr[i]>1) {
        ans = true;
        break;
      }
    }
    if(!ans){
      console.log(-1);
      continue;
    }
    for(let i=1;i<n-1;i++){
      cnt+=Math.ceil(arr[i]/2);
    }
    console.log(cnt);
};
}
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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    //Write your code here
    const t = parseInt(readline());
    for(let i = 0; i < t; i++){
        const n = parseInt(readline());
        const arr = readline().split(" ").map((v)=>parseInt(v));
        let ret = 0;
        if(arr.slice(1,arr.length-1).every(v=>v==1)){
            console.log(-1);
            continue;
        }
        if(arr.length==3){
            console.log(arr[1]%2==0?arr[1]/2:-1)
            continue;
        } else {
            for(let i = 1; i < arr.length-1; i++){
                if(arr[i])
                ret+=arr[i]%2==0?arr[i]/2:(arr[i]+1)/2;
            }
        }
        console.log(ret);
    }
}

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;
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

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

		let ans = 0;
		if (Math.max(...a.slice(1, n-1)) == 1 || n == 3 && a[1]&1) {
			ans = -1;
		} else {
			for (let i = 1; i < n-1; i++) {
				ans += Math.ceil(a[i]/2);
			}
		}

		console.log(ans);
	}
}

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;
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

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

		let sum = 0, odds = 0;
		for (let i = 1; i < n-1; i++) {
			sum += a[i];
			odds += a[i]&1;
		}

		if ((n==3 && sum&1) || sum == n-2) {
			console.log(-1);
		} else {
			console.log(Math.floor(sum/2) + Math.ceil(odds/2));
		}
	}
}


function rda(){ return readline().split(" ").map(Number); }
function rdn(){ return +readline(); }

var inp = rda(), n = inp[0], m = inp[1];
delete inp;

var ver = [], hor = [];
for(var i = 1; i <= n; i++){
    ver[i] = 0;
    hor[i] = 0;
}

var total = n*n;
var v = 0, h = 0;
var ans = [];
for(var i = 0; i < m; i++){
    var inp = rda(), x = inp[0], y = inp[1];
    delete inp;

    if(hor[x] == 0){
        hor[x] = 1;
        h++;
    }
    if(ver[y] == 0){
        ver[y] = 1;
        v++;
    }
    ans.push( total - (h*n + v*n - v*h) );
}

write(ans.join(" "));

var nm = readline().split(" ").map(function(x) { return parseInt(x); });
var n = parseInt(nm[0]);
var m = parseInt(nm[1]);

//var n = 5;
//var m = 2;
//var a = [[1, 5], [5, 1]];

//var n = 3;
//var m = 3;
//var a = [[1, 1], [3, 1], [2, 2]];

//var n = 100000;
//var m = 1;
//var a = [[300, 400]];

//var n = 2;
//var m = 2;
//var a = [[1, 1], [1, 2]];

var rows = {};
var cols = {};

var rowsCount = 0;
var colsCount = 0;

var t = n * n;
var results = [];

for (var i = 0; i < m; ++i) {
    //var coor = a[i];
    var coor = readline().split(" ").map(function(x) { return parseInt(x); });

    var x = coor[0];
    var y = coor[1];

    if (rows[x] == undefined) {
        ++rowsCount;
        t -= (n - colsCount);
    }

    if (cols[y] == undefined) {
        ++colsCount;
        t -= (n - rowsCount);
    }

    results.push(t);

    rows[x] = 1;
    cols[y] = 1;
}

print(results.join(" "));
//console.log(results.join(" "));

var nm = readline().split(" ").map(function(x) { return parseInt(x); });
var n = parseInt(nm[0]);
var m = parseInt(nm[1]);

//var n = 5;
//var m = 2;
//var a = [[1, 5], [5, 1]];

//var n = 3;
//var m = 3;
//var a = [[1, 1], [3, 1], [2, 2]];

//var n = 100000;
//var m = 1;
//var a = [[300, 400]];

//var n = 2;
//var m = 2;
//var a = [[1, 1], [1, 2]];

var rows = {};
var cols = {};

var rowsCount = 0;
var colsCount = 0;

var t = n * n;
//var results = [];

for (var i = 0; i < m; ++i) {
    //var coor = a[i];
    var coor = readline().split(" ").map(function(x) { return parseInt(x); });

    var x = coor[0];
    var y = coor[1];

    if (rows[x] == undefined) {
        ++rowsCount;
        t -= (n - colsCount);
    }

    if (cols[y] == undefined) {
        ++colsCount;
        t -= (n - rowsCount);
    }

    //results.push(t);
    write(t+" ");

    rows[x] = 1;
    cols[y] = 1;
}

//print(results.join(" "));
//console.log(results.join(" "));

var nm = readline().split(' ').map(
	function(x){
		return parseInt(x);
	}
);
var n = nm[0];
var m = nm[1];
var t = n*n;
var row = [];
var col = [];
var urow = n;
var ucol = n;
function pr(el, i, a){
	write(el + " ");
};
for(i = 0; i < m; ++i){
	var coord = readline().split(' ').map(function(x){return parseInt(x)});
	var x = coord[0] - 1;
	var y = coord[1] - 1;
	if(row[x] == undefined){
		t -= ucol;
		row[x] = 1;
		urow--;
	};
	if(col[y] == undefined){
		t -= urow;
		col[y] = 1;
		ucol--;
	};
	write(t + " ");
};
print();

var nm = readline().split(" ").map(function(x) { return parseInt(x); });
var n = nm[0];
var m = nm[1];

//var a = [[1, 1], [3, 1], [2, 2]];

var rows = {};
var cols = {};

var t = n * n;
for (var i = 0; i < m; ++i) {
    //var coor = a[i];
    var coor = readline().split(" ").map(function(x) { return parseInt(x); });

    var x = coor[0];
    var y = coor[1];

    if (i > 0) {
        if (rows[x] == undefined || cols[y] == undefined) {
            t -= n - 1;
        }
    } else {
        t -= 2 * n - 1;
    }

    print(t);
    //console.log(t);

    if (t == 0) break;

    rows[x] = 1;
    cols[y] = 1;
}

var nm = readline().split(" ").map(function(x) { return parseInt(x); });
var n = parseInt(nm[0]);
var m = parseInt(nm[1]);

//var n = 5;
//var m = 2;
//var a = [[1, 5], [5, 1]];

//var n = 3;
//var m = 3;
//var a = [[1, 1], [3, 1], [2, 2]];

//var n = 100000;
//var m = 1;
//var a = [[300, 400]];

var rows = {};
var cols = {};

var t = n * n;
var offset = n;
var results = [];

for (var i = 0; i < m; ++i) {
    //var coor = a[i];
    var coor = readline().split(" ").map(function(x) { return parseInt(x); });

    var x = coor[0];
    var y = coor[1];

    if (rows[x] == undefined) {
        t -= offset;
    }

    if (cols[y] == undefined) {
        offset -= 1;
        t -= offset;
        if (t < 0) t = 0;
    }

    results.push(t);

    if (t == 0) break;

    rows[x] = 1;
    cols[y] = 1;
}

print(results.join(" "));

var nm = readline().split(" ").map(function(x) { return parseInt(x); });
var n = parseInt(nm[0]);
var m = parseInt(nm[1]);

//var n = 5;
//var m = 2;
//var a = [[1, 5], [5, 1]];

//var n = 3;
//var m = 3;
//var a = [[1, 1], [3, 1], [2, 2]];

//var n = 100000;
//var m = 1;
//var a = [[300, 400]];

//var n = 2;
//var m = 2;
//var a = [[1, 1], [1, 2]];

var rows = {};
var cols = {};

var t = n * n;
var offsetX = n;
var offsetY = n;
var results = [];

for (var i = 0; i < m; ++i) {
    //var coor = a[i];
    var coor = readline().split(" ").map(function(x) { return parseInt(x); });

    var x = coor[0];
    var y = coor[1];

    if (rows[x] == undefined) {
        t -= offsetY;
        offsetX -= 1;
    }

    if (cols[y] == undefined) {

        if(rows[x] != undefined) {
            t -= offsetX;
        }

        offsetY -= 1;
        t -= offsetY;
        if (t < 0) t = 0;
    }

    results.push(t);

    if (t == 0) break;

    rows[x] = 1;
    cols[y] = 1;
}

print(results.join(" "));
//console.log(results.join(" "));

var nm = readline().split(" ").map(function(x) { return parseInt(x); });
var n = parseInt(nm[0]);
var m = parseInt(nm[1]);

//var n = 5;
//var m = 2;
//var a = [[1, 5], [5, 1]];

//var n = 3;
//var m = 3;
//var a = [[1, 1], [3, 1], [2, 2]];

//var n = 100000;
//var m = 1;
//var a = [[300, 400]];

//var n = 2;
//var m = 2;
//var a = [[1, 1], [1, 2]];

var rows = {};
var cols = {};

var rowsCount = 0;
var colsCount = 0;

var t = n * n;
//var results = [];

for (var i = 0; i < m; ++i) {
    //var coor = a[i];
    var coor = readline().split(" ").map(function(x) { return parseInt(x); });

    var x = coor[0];
    var y = coor[1];

    if (rows[x] == undefined) {
        ++rowsCount;
        t -= (n - colsCount);
    }

    if (cols[y] == undefined) {
        ++colsCount;
        t -= (n - rowsCount);
    }

    //results.push(t);
    write(t);

    rows[x] = 1;
    cols[y] = 1;
}

//print(results.join(" "));
//console.log(results.join(" "));


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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var one = nextIntArray();
    var a = one[0];
    var b = one[1];
    var c = one[2];
    var d = one[3];
    var k = one[4];
    var L = Math.ceil(a / c);
    var R = Math.ceil(b / d);
    if(L + R <= k){
      output[i] = L + " " + R;
    }else{
      output[i] = -1;
    }
  }
  myout(myconv(output, 9));
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [1, 1, 1, 1, 2],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] % query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = xLeftover ? x + 1 : x;

  write(x + y  > query[4] ? [-1].join(' ') + '\n' : [x, y].join(' ') + '\n');

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

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

const main = (input) => {
	for (var i = 1; i <= parseInt(input[0]); i++) {
		var [a, b,c,d, k] = input[i].split(" ").map(num => parseInt(num));
		var aTotal = Math.ceil(a / c);
		var bTotal = Math.ceil(b / d);
		if (aTotal + bTotal <= k) {
			console.log(aTotal, bTotal);
		} else {
			console.log(-1);
		}
	}
}

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

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

  const [a, b, c, d, k] = data.split(' ').map(Number);
  const x = Math.ceil(a / c);
  const y = Math.ceil(b / d);

  if (x + y > k) {
    console.log(-1);
  }
  else {
    console.log(x, y);
  }

  count++;
});

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

const sol = () => {
	let line = data.split(/\n/);
    let n = Number(line[0]);
    let ans = [];
    for(let i = 0; i < n; i++){
		let [a, b, c, d, k] = line[i+1].split(/\s/).map(v => Number(v));
		let x = Math.ceil(a/c);
		let y = Math.ceil(b/d);
		if (x + y > k) {
			ans.push(-1);
		} else {
			ans.push(`${x} ${y}`);
		}
	}
	console.log(ans.join('\n'));
};

process.stdin.on('end',sol);

'use strict'

const problem = (a, b, c, d, k) => ((x, y) => (k >= x + y) ? `${x} ${y}` : -1)(Math.ceil(a/c), Math.ceil(b/d));

let t = parseInt(readline());
while (t--) {
    const abcdk = readline().split(' ').map(Number);
    write(problem(abcdk[0], abcdk[1], abcdk[2], abcdk[3], abcdk[4]) + '\n');
}

var t = +readline();

while(t--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1)
     else print(`${x} ${y}`)

}

function findMin(i, j) {
    return Math.ceil(i/j);
}

var q = readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1);
     else write(x, y);

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var q = +readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = Math.ceil(a/c), y = Math.ceil(b/d);
     if(x + y > k) write(-1 + '\n');
     else write(x + ' ' + y + '\n');
}

var q = readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1);
     else print(x, y);

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var q = +readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c);
     // , y = findMin(b, d);
     // if(x + y > k) print(-1);
     // else print(x, y);
     print(x,x);

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var q = readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1)
     else print(`${x} ${y}`)

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var q = +readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = Math.ceil(a/c), y = Math.ceil(b/d);
     if(x + y > k) print(-1);
     else print(x, y);
}

var q = +readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     // var x = findMin(a, c), y = findMin(b, d);
     // if(x + y > k) print(-1);
     // else print(x, y);
     print(a,b);

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var q = readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) write(-1 + '\n');
     else write(x + ' ' + y + '\n');

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var q = readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1)
     else print(`${x} ${y}`)

}

function findMin(i, j) {
     var ans;

     if(j > i) ans = 1;
     else {
          ans = i/j;
          ans += i%j ? 1:0;
     }

     return ans;
}

var t = +readline();

while(t--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1)
     else print(`${x} ${y}`)

}

function findMin(i, j) {
     var ans;

     if(j > i) ans = 1;
     else {
          ans = i/j;
          ans += i%j ? 1:0;
     }

     return ans;
}

var q = +readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1);
     else print(x, y);

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = yLeftover ? x + 1 : x;

  write(x + y  > query[4] ? "-1" : [x, y].join(' '));

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = xLeftover ? x + 1 : x;

  write(x + y  > query[4] ? [-1].join('') : [x, y].join(' ') + '\n');

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = xLeftover ? x + 1 : x;

  write(x + y  > query[4] ? "-1\n" : [x, y].join(' ') + '\n');

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = xLeftover ? x + 1 : x;

  write(x + y  > query[4] ? [-1].join(' ') + '\n' : [x, y].join(' ') + '\n');

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = yLeftover ? x + 1 : x;

  write(x + y  > query[4] ? -1 : [x, y].join(' '));

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = yLeftover ? x + 1 : x;

  write(x + y  > query[4] ? "\n-1\n" : [x, y].join(' '));

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = yLeftover ? x + 1 : x;

  write(x + y  > query[4] ? "-1\n" : [x, y].join(' '));

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = xLeftover ? x + 1 : x;

  write(x + y  > query[4] ? [-1].join(' ') : [x, y].join(' ') + '\n');

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = yLeftover ? x + 1 : x;

  write(x + y  > query[4] ? "-1\n" : [x, y].join(' ') + '\n');

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

'use strict'

const problem = (a, b, c, d, k) => ((x, y) => (k <= x + y) ? `${x} ${y}` : -1)(Math.ceil(a/c), Math.ceil(b/d));

let t = parseInt(readline());
while (t--) {
    const abcdk = readline().split(' ').map(Number);
    write(problem(abcdk[0], abcdk[1], abcdk[2], abcdk[3], abcdk[4]) + '\n');
}


'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();
  return n + (Math.floor(n / 2) + Math.floor(n / 3)) * 2;
}
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 = 100;
    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);
}();

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let i=1;i<=t;i++)
    {
        let n=parseInt(line[i]);
        let ans=0;
        ans+=n;
        ans+=2*Math.floor(n/2);
        ans+=2*Math.floor(n/3);
        console.log(ans);
    }
})

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    // console.log(line);
    let t=parseInt(line[0]);
    for(let i=1;i<=t;i++)
    {
        let n=parseInt(line[i]);
        let ans=0;
        ans+=n;
        ans+=2*Math.floor(n/2);
        ans+=2*Math.floor(n/3);
        // ans+=Math.floor(y/3);
        console.log(ans);
    }
})

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var last = 0;
	var addlist = [0,1,4,7,10,11,16];
	while(hasNext()){
		var N = nextInt();
		var output = Math.floor(N / 6) * 16;
		output += addlist[N % 6];
		myout(output);
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);

        let count = n; //('equals');
        count += Math.floor(n / 2) * 2;
        count += Math.floor(n / 3) * 2;

        output(count);
    }
}

var n = readline();
for(var i=0;i<n;i++){
  var N = parseInt(readline());
  print(N+2*Math.floor(N/2)+2*Math.floor(N/3));
}


function countErasedZeroes(str) {
  var len = str.length, start = -1, end = -1, count = 0
  for (var i=0; i<len; i++) {
    if (str[i] === '1') {
        start = i
        break
    }
  }
  for (var i=len-1; i>=0; i--) {
    if (str[i] === '1') {
        end = i
        break
    }
  }
  for (i=start; i<=end; i++) {
    if (str[i] === '0')
        ++count
  }
  return count
}

var tc = Number(readline())
while (tc--) {
  var str = readline()
  print(countErasedZeroes(str))
}

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split(/[\r\n]/).filter(data => data.length > 0);

txt.shift();
for (let i = 0; i < txt.length; i++) {
    doit(txt[i].split("").filter(data => data.length > 0));

}

function doit(arr) {
    let shift = 0;
    let current = null;
    arr.forEach((data, index) => {
        if (data == 1) {
            if (current == null) {
                current = index;
            } else {
                shift += index - current - 1;
                current = index;
            }
        }
    });
    console.log(shift);

}

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

var input= '', readline, print;

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

process.stdin.on('end', function() {
  input = input.split('\n');
  print = function(data) {process.stdout.write(data+'\n')};
  var inputLineIndex = 0;
  readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};
  process.exit(main() || 0);
});

function main()
{
  const length = input[0];
  for(let i = 1; i <= length; i++) {
    const str = input[i];
    let count = 0;
    let firstIndex = -1;
    let lastIndex = -1;

    for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {
      if(str[j] === '1' && firstIndex < 0) {
        firstIndex = j;
      }

      if(str[j2] === '1' && lastIndex < 0) {
        lastIndex = j2;
      }
    }

    for(let i = firstIndex; i <= lastIndex; i++) {
      if(str[i] === '0') count++;
    }

    print(count);
  }

  // Your code here
  return 0;
}

var data = "";

process.stdin.on("data", x => data += x);

// process.on("SIGINT", () => {
process.stdin.on("end", () => {

	var lines = data.split("\r\n");

	var n = lines.shift();
	for(let i = 0; i < n; i++) f(lines[i]);

	process.exit(0);
});

function f(line) {

	line = line.replace(/(^0*|0*$)/g, "");

	var ans = 0;

	while(line.length) {

		if(+line[0]) line = line.replace(/^1+/, "");
		else {

			var m = line.match(/^0+/);
			ans += m[0].length;
			line = line.replace(/^0+/, "");
		}
	}
	console.log(ans);
}

const main = (data) => {
  const n = data[0];

  for (let i = 1; i <= n; i++) {
    const str = data[i];
    const lastIndex = str.lastIndexOf('1');
    let result = 0;

    for (let j = str.indexOf('1'); j < lastIndex; j++) {
      if (str[j] === '0') {
        result++;
      }
    };

    console.log(result);
  };
};

let data = '';

process.stdin.on('data', input => data += input);
process.stdin.on('end', () => {
  data = data.split('\n');

  main(data);
});

const readline = require('readline');

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

let state = 0;
rl.on('line', line => {
  if (state > 0) {
    let left = line.indexOf('1');
    let right = line.lastIndexOf('1');
    let match = line.slice(left, right).match(/0/g) || [];
    console.log(match.length);
  }
  state++;
}).on('close', () => {
  process.exit(0);
});

const readline = require('readline');

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

let state = 0;
rl.on('line', line => {
  if (state > 0) {
    let left = line.indexOf('1');
    let right = line.lastIndexOf('1');

    console.log(
      line
        .slice(left, right)
        .split('')
        .reduce((a, b) => {
          return (a += b == '0' ? 1 : 0);
        }, 0)
    );
  }
  state++;
}).on('close', () => {
  process.exit(0);
});

const fs = require("fs");
const input = fs.readFileSync(0, { encoding: "utf-8" });
const lines = input.split("\n");
let cases = Number(lines.shift());

while (cases--) {
  const line = lines.shift();
  let a = 0, b = 0, found1 = false;
  for (let i = 0; i < line.length; i++) {
    if (line[i] === "1") {
      found1 = true;
      b = a;
    } else if (found1) {
      a++;
    }
  }
  console.log(b);
}

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

    function foo (str) {
        const match = str.match(/^0*(.*?)0*$/);
        const trimed = match && match[1];
        if (!trimed) return 0;
        const theros = trimed.match(/0/g);
        if (!theros) return 0;
        return theros.length;
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let data = lines[testCount];

        let result = foo(data);
        answer += result +"\n";
        testCount++;
    }
    console.log(answer);
})

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

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

  let ans = 0;
  let headN = str.indexOf('1');
  let tailN = str.lastIndexOf('1');

  for (let i = headN; i < tailN; i++) {
    if (str[i] === '0') {
      ans++;
    }
  }

  console.log(ans);

  c++;
});

const processData = (lines) => {
  const num = +lines[0]

  for (let j=0; j<num; j++){
    const numsLine = lines[j+1].split('')
    let isFindOne = false
    let res = 0
    let acc = 0
    for (const n of numsLine) {
      if (n === '0') {
        if (isFindOne) {
          acc++
        }
      } else {
        isFindOne = true
        res += acc
        acc = 0
      }

    }
    console.log(res)
  }
}

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

var tests = parseInt(readline())
for (var l = 0; l < tests; l++){
var input = readline()
var res = input.split(/(0+)/)
var start = false, erase = 0, head = 0;
for (var i = 0; i < res.length; i++){
	if (res[i][0] == '1' && !start){
		start = true; head = i
	}
	else if (res[i][0] == '1' && start){
		if (i - head > 1){
			erase += res[i-1].length
			head = i
		}
	}
}
print(erase)
}

'use strict'

const problem = (s) => s.split(/1+/).slice(1, -1).reduce((r, i) => r + i.length, 0);

let t = +readline()
while(t--) print(problem(readline()))

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main() {
    var t = myconv(next(),1);
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var list = myconv(next(),6);
        var count = 0;
        var tmpCount = 0;
        var zero = false;
        var one = false;
        for(var j = 0; j < list.length; j++){
            if(list[j] == "1"){
                if(zero){
                    zero = false;
                    count += tmpCount;
                    tmpCount = 0;
                }
                one = true;
            }
            if(list[j] == "0"){
                if(one){
                    tmpCount++;
                }
                zero = true;
            }
        }
        output[i] = count;
    }
    myout(myconv(output,9));
}

function countErasedZeroes(str) {
  var len = str.length,
      start = -1,
      end = -1,
      count = 0
  for (var i = 0; i < len; i++) {
      if (str[i] === '1') {
          start = i
          break
      }
  }
  for (var i = len - 1; i >= 0; i--) {
      if (str[i] === '1') {
          end = i
          break
      }
  }
  for (i = start; i <= end; i++) {
      if (str[i] === '0')
          ++count
  }
  return count
}

var tc = Number(readline())
while (tc--) {
  var str = readline()
  print(countErasedZeroes(str))
}

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

var input= '', readline, print;

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

process.stdin.on('end', function() {
  input = input.split('\n');
  print = function(data) {process.stdout.write(data+'\n')};
  var inputLineIndex = 0;
  readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};
  process.exit(main() || 0);
});

function main()
{
  const length = input[0];
  for(let i = 1; i <= length; i++) {
    const str = input[i];
    let count = 0;
    let firstIndex = null;
    let lastIndex = null;

    for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {
      if(str[j] === '1' && !firstIndex) {
        firstIndex = j;
      }

      if(str[j2] === '1' && !lastIndex) {
        lastIndex = j2;
      }
    }

    for(let i = firstIndex; i <= lastIndex; i++) {
      if(str[i] === '0') count++;
    }

    print(count);
  }

  // Your code here
  return 0;
}

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

var input= '', readline, print;

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

process.stdin.on('end', function() {
  input = input.split('\n');
  print = function(data) {process.stdout.write(data+'\n')};
  var inputLineIndex = 0;
  readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};
  process.exit(main() || 0);
});

function main()
{
  for(let i = 1; i < input.length - 1; i++) {
    const str = input[i];
    let count = 0;
    let firstIndex = null;
    let lastIndex = null;

    for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {
      if(str[j] === '1' && !firstIndex) {
        firstIndex = j;
      }

      if(str[j2] === '1' && !lastIndex) {
        lastIndex = j2;
      }
    }

    for(let i = firstIndex; i < lastIndex; i++) {
      if(str[i] === '0') count++;
    }

    print(count);
  }

  // Your code here
  return 0;
}

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

var input= '', readline, print;

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

process.stdin.on('end', function() {
  input = input.split('\n');
  print = function(data) {process.stdout.write(data+'\n')};
  var inputLineIndex = 0;
  readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};
  process.exit(main() || 0);
});

function main()
{
  const length = input[0];
  for(let i = 1; i <= length; i++) {
    const str = input[i];
    let count = 0;
    let firstIndex = null;
    let lastIndex = null;

    for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {
      if(str[j] === '1' && !firstIndex) {
        firstIndex = j;
      }

      if(str[j2] === '1' && !lastIndex) {
        lastIndex = j2;
      }
    }

    for(let i = firstIndex; i < lastIndex; i++) {
      if(str[i] === '0') count++;
    }

    print(count);
  }

  // Your code here
  return 0;
}

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

var input= '', readline, print;

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

process.stdin.on('end', function() {
  input = input.split('\n');
  print = function(data) {process.stdout.write(data+'\n')};
  var inputLineIndex = 0;
  readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};
  process.exit(main() || 0);
});

function main()
{
  for(let i = 1; i < input.length; i++) {
    const str = input[i];
    let count = 0;
    let isRow = false;

    for (let j = 0; j < str.length; j++) {
      if(str[j] === '1' && !isRow) {
        isRow = true;
      } else if(str[j] === '0' && isRow) {
        count++;
      }
    }
    print(count);
  }

  // Your code here
  return 0;
}

let fs=require('fs')
let txt=fs.readFileSync(0,"utf-8").split(/[\r\n]/).filter(data=>data.length>0);

txt.shift()
for (let i = 0; i < txt.length; i++) {
    doit(txt[i].split("").filter(data=>data.length>0));

}

function doit(arr){
    let shift=0;
    let current=null;
    arr.forEach((data,index) => {
        if(data==1){
            if(current==null){current=index}else{
                shift+=index-current-1;
                current=null;
            }
        }
    });
    console.log(shift);

}