var input = readline().split(' ').map(Number);
var n = input[0], k = input[1];
var h = readline().split(' ').map(Number);
var j = 0;
var min_sum = h.slice(0, k).reduce((a, b) => a + b);
var sum = min_sum;
for (var i = k; i < n; i++) {
    sum = sum - h[i - k] + h[i];
    if (sum < min_sum) {
        min_sum = sum;
        j = i - k + 1
    }
}
print(j + 1);

var n = readline().split(/\s/gi).map(Number),
			k = n[1], n = n[0],
			heights = readline().split(/\s/gi).map(Number),
			sumH = heights.slice(0, k).reduce(function(a, b) { return a + b; }),
			tArr = [ sumH ], resultIndex = 0;

		for(var i = 1; i <= n - k; i++)	{
			var prevSumH = tArr[tArr.length - 1],
				minSumH;

			sumH = sumH - heights[i - 1] + heights[i + k - 1];
			minSumH = Math.min(prevSumH, sumH);
			// console.log(heights.slice(k - 1, k - 1 + k));
			// console.log(sumH);

			if(sumH == minSumH)	resultIndex = i;
			tArr.push(minSumH);
		}

		print(resultIndex + 1);

var optimalStartPoint = function ( planks, k ) {
  var optimal,
    minSum,
    sum,
    i;

   minSum = 0;
   optimal = 0;
   for ( i = 0; i < k; ++i ) {
     minSum += planks[ i ];
   }
   sum = minSum;

   for ( i = 1; i < planks.length - k + 1; ++i ) {
     sum = sum - planks[ i - 1 ] + planks[ i + k - 1 ];
     if ( sum < minSum ) {
       minSum = sum;
       optimal = i;
     }
   }
   return optimal;
};

var input = readline().split( " " ).map( i => parseInt( i, 10 ) );
var k = input[ 1 ];
var planks = readline().split( " " ).map( hi => parseInt( hi, 10 ) );
print( optimalStartPoint( planks, k ) + 1 );

print(function(n, k) {
	var sum = 0,
		ans = 0,
		min = 1e8,
		d = ('0 ' + readline()).split(' ').map(Number).map(function(v) {
			return sum += v;
		}).map(function(v, i, s) {
			return i + k <= n ? s[i + k] - s[i] : 1e8;
		});

	for (var i = 0; i <= n - k + 1; i++) {
		if (d[i] < min)
			min = d[i], ans = i;
	}
	return ans + 1;

}.apply(0, readline().split(' ').map(Number)));

print(function(n, k) {

	var sum = 0,
		ans = 0,
		min = 1e8,
		d = ('0 ' + readline()).split(' ').map(Number).map(function(v) {
			return sum += v;
		}).map(function(v, i, s) {
			return i + k <= n ? s[i + k] - s[i] : 1e8;
		});

	for (var i = 0; i <= n - k + 1; i++)
		if (d[i] < min)
			min = d[i],
			ans = i;

	return ans + 1;

}.apply(0, readline().split(' ').map(Number)));

(function main() {
    var nk = readline().split(' ').map(function(x) {return parseInt(x);});
    var n = nk[0];
    var k = nk[1];
    var a = readline().split(' ').map(function(x) {return parseInt(x);});
    var s = 0;
    var mins = s;
    var mini = 1;
    for (var i = k; i < n; ++i) {
        s += a[i] - a[i - k];
        if (s < mins) {
            mins = s;
            mini = i - k + 2;
        }
    }
    print(mini);
})();

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

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

for(var i = 0, s = 0; i < n; i++){
    s += h[i];
    h[i] = s;
}

var val = h[k-1];
var ans = k-1;
for(var i = k; i < n; i++){
    if((h[i]-h[i-k]) < val){
        val = h[i]-h[i-k];
        ans = i;
    }
}

write(ans+2-k);

(function main() {
    var toInt = function(x) {
        return parseInt(x);
    }
    var firstline = readline().split(" ").map(toInt);
    var n = firstline[0],
        k = firstline[1];

    var ar = readline().split(" ").map(toInt);
    // NOT ar.sort(function(a, b){return a-b});

    // ar = [1, 2, 6, 1, 1, 7, 1];
    // k = 3;
    ar.reduce(function(sum, next, id, array) {
        var tmp = sum + next;
        array[id] = tmp;
        return tmp;
    });

    ar.splice(0,0,0);

    print((function() {
        var count = 999999999;
        var index = -1;
        for(var i = k; i < ar.length; ++i) {
            var tmp = ar[i]-ar[i-k]
            if (count > tmp) {
                index = i - k + 1;
                count = tmp;
            }
        }
        return index;
    })());
})();

var input = readline().split(' ').map(Number);
var n = input[0];
var k = input[1];
var a = readline().split(' ').map(Number);
var ans = 0;
var minsum = a.slice(0, k).reduce((a, b) => a + b);
var sum = minsum;
for (var i = k; i < a.length; i++) {
	var sum = sum + a[i] - a[i - k];
	if (sum < minsum) {
		minsum = sum;
		ans = i - k + 1;
	}
}

print(ans + 1);

var input = readline().split(' ').map(Number);
var n = input[0], k = input[1];
var h = readline().split(' ').map(Number);
var j = 0, min_sum = 0, sum = 0;
for (var i = k; i < n; i++) {
    sum = sum - h[i - k] + h[i];
    if (sum < min_sum) {
        min_sum = sum;
        j = i - k + 1
    }
}
print(j + 1);

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

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

function main() {
  const [len, k] = readLine().split(" ").map(Number);
  const arr = readLine().split(" ").map(Number);
  let [min, minIndex, sum] = [Infinity, 0, 0];

  for (let i = 0; i < k; i++) sum += arr[i];

  min = sum;
  for (let i = k; i < len; i++) {
    sum = sum + arr[i] - arr[i - k];
    if (sum < min) {
      min = sum;
      minIndex = i - k + 1;
    }
  }

  console.log(minIndex + 1);
}

var x = new Array();
var n,k;
var buff = new Array();
function read() {
	return readline().split(' ').map(Number);
}
function main() {
	buff=read();
	n=buff[0],k=buff[1];
	buff=read();
	x[0]=0;
	for (var i=1; i<=n; i++) {
		x[i]=x[i-1]+buff[i-1];
	}
	var ans=1<<31-1,pos=0;
	for (var i=1; i<=n-k+1; i++) {
		if (ans>x[i+k-1]-x[i-1]) {
			ans=x[i+k-1]-x[i-1];
			pos=i;
		}
	}
	print(pos);
}
main();

const input = [];

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

RL.on('line', line => input.push(line));

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

  let memory = 0; minSum = 0; let pos = 1;
  for (let i = 0; i < k; i += 1) {
    memory += nums[i];
  }
  minSum = memory;

  let j = 0;
  for (let i = k; i < n; i += 1) {
    memory = memory - nums[j] + nums[i];
    if (memory < minSum) {
      minSum = memory; pos = j + 2;
    }
    j += 1;
  }

  console.log(pos);
});

;(function () {

    print(function (n, k) {
        var h = readline().split(' ').map(Number),
            r = 0, t = 0, l = 0;

        for (var i = 0; i < k; i++) {
            r += h[i];
        }

        l = r;

        for (var i = 1, _i = n - k + 1; i < _i; i++) {
            var d = r - h[i - 1] + h[i + k - 1];
            if (d < l) {
                t = i;
                l = d;
            }

            r = d;
        }

        return t + 1;
    }.apply(null, readline().split(' ').map(Number)));

}.call(this));

function main() {
    var line = readline().split(' ').map(Number);
    var n = line[0];
    var k = line[1];
    var data = readline().split(' ').map(Number);
    var sum = 0;
    for(var i=0;i<k-1;i++){
        sum += data[i];
    }
    var min = Number.MAX_VALUE
    var res = 1;
    for(var i=0;i<=n-k;i++){
        sum += data[i+k-1];
        if(sum < min){
            min = sum;
            res = i+1;
        }
        sum -= data[i];
    }
    print(res)
}

main()

print(function(n, k) {
	var sum = 0,
		ans = 0,
		min = 1e6,
		d = ('0 ' + readline()).split(' ').map(Number).map(function(v) {
			return sum += v;
		}).map(function(v, i, s) {
			return i + k <= n ? s[i + k] - s[i] : 1e6;
		});

	for (var i = 0; i <= n - k; i++)
		if (d[i] < min)
			min = d[i], ans = i;

	return ans + 1;

}.apply(0, readline().split(' ').map(Number)));

print(function(n, k) {
	var sum = 0,
		ans = 0,
		min = 1e8,
		d = ('0 ' + readline()).split(' ').map(Number).map(function(v) {
			return sum += v;
		}).map(function(v, i, s) {
			return i + k <= n ? s[i + k] - s[i] : 1e6;
		});

	for (var i = 0; i <= n - k + 1; i++) {
		if (d[i] < min)
			min = d[i], ans = i;
	}
	return ans + 1;

}.apply(0, readline().split(' ').map(Number)));

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

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

for(var i = 0, s = 0; i < n; i++){
    s += h[i];
    h[i] = s;
}

var val = h[k-1];
var ans = k-1;
for(var i = k; i < n; i++){
    if((h[i]-h[i-k]) < val){
        val = h[i]-h[i-k];
        ans = i;
    }
    print(val, ans);
}

write(ans+2-k);

(function main() {
    var toInt = function(x) {
        return parseInt(x);
    }
    var firstline = readline().split(" ").map(toInt);
    var n = firstline[0],
        k = firstline[1];

    var ar = readline().split(" ").map(toInt);
    // NOT ar.sort(function(a, b){return a-b});

    ar.reduce(function(sum, next, id, array) {
        var tmp = sum + next;
        array[id] = tmp;
        return tmp;
    });

    // ar.splice(0,0,0);

    print((function() {
        var count = -1;
        var index = -1;
        for(var i = k-1; i < ar.length; ++i) {
            var tmp = ar[i]-ar[i-k+1]
            if (count < tmp) {
                index = i - k + 1;
                count = tmp;
            }
        }
        return index + 1;
    })());
})();

var input = readline().split(' ').map(Number);
var n = input[0];
var k = input[1];
var a = readline().split(' ').map(Number);
var ans = 2;
var minsum = a.slice(0, k).reduce((a, b) => a + b);
for (var i = k; i < a.length; i++) {
	var sum = minsum + a[i] - a[i - k];
	if (sum < minsum) {
		minsum = sum;
		ans = i;
	}
}

print(ans - 1);

var input = readline().split(' ').map(Number);
var n = input[0];
var k = input[1];
var a = readline().split(' ').map(Number);
var ans = 0;
var minsum = a.slice(0, k).reduce((a, b) => a + b);
for (var i = k; i < a.length; i++) {
	var sum = minsum + a[i] - a[i - k];
	if (sum < minsum) {
		minsum = sum;
		ans = i;
	}
}

print(ans - 1);

var input = readline().split(' ').map(Number);
var n = input[0];
var k = input[1];
var a = readline().split(' ').map(Number);
var ans = 2;
var minsum = a.slice(0, k).reduce((a, b) => a + b);
var sum = minsum;
for (var i = k; i < a.length; i++) {
	var sum = sum + a[i] - a[i - k];
	if (sum < minsum) {
		minsum = sum;
		ans = i;
	}
}

print(ans - 1);

var x = new Array();
var n,k;
var buff = new Array();
function read() {
	return readline().split(' ').map(Number);
}
function main() {
	buff=read();
	n=buff[0],k=buff[1];
	buff=read();
	for (var i=0; i<n; i++) {
		x[i]=buff[i];
	}
	for (var i=1; i<n; i++) {
		x[i]=x[i-1]+x[i];
	}
	var pos=0,ans=1<<31-1;
	for (var i=0; i<n-k+1; i++) {
		if (x[i+k-1]-x[i]<ans) {
			ans=x[i+k-1]-x[i];
			pos=i;
		}
	}
	print(pos+1);
}
main();

;(function () {

    print(function (n, k) {
        var h = readline().split(' ').map(Number),
            r = 0, t = 0;

        for (var i = 0; i < k; i++) {
            r += h[i];
        }

        for (var i = 1, _i = n - k + 1; i < _i; i++) {
            var d = r - h[i - 1] + h[i + k - 1];
            if (d < r) {
                t = i;
            }

            r = d;
        }

        return t + 1;
    }.apply(null, readline().split(' ').map(Number)));

}.call(this));

;(function () {

    print(function (n, k) {
        var h = readline().split(' ').map(Number),
            r = 0, t = 0;

        for (var i = 0; i < k; i++) {
            r += h[i];
        }

        for (var i = 1, _i = n - k + 1; i < _i; i++) {
            var d = r - h[i - 1] + h[i + k];
            if (d < r) {
                t = i;
            }

            r = d;
        }

        return t + 1;
    }.apply(null, readline().split(' ').map(Number)));

}.call(this));

;(function () {

    print(function (n, k) {
        var h = readline().split(' ').map(Number),
            r = 0, t = 0;

        for (var i = 0; i < k; i++) {
            r += h[i];
        }

        for (var i = 1, _i = n - k; i < _i; i++) {
            var d = r - h[i] + h[i + k - 1];
            if (d < r) {
                t = i;
            }

            r = d;
        }

        return t + 1;
    }.apply(null, readline().split(' ').map(Number)));

}.call(this));

;(function () {

    print(function (n, k) {
        var h = readline().split(' ').map(Number),
            r = 0, t = 0;

        for (var i = 0; i < k; i++) {
            r += h[i];
        }

        for (var i = 1, _i = n - k + 1; i < _i; i++) {
            var d = r - h[i - 1] + h[i + k - 1];
            if (d < r) {
                t = i;
            }

            if (d === 1) {
                return t + 1;
            }

            r = d;
        }

        return t + 1;
    }.apply(null, readline().split(' ').map(Number)));

}.call(this));

;(function () {

    print(function (n, k) {
        var h = readline().split(' ').map(Number),
            r = 0, t = 0;

        for (var i = 0; i < k; i++) {
            r += h[i];
        }

        for (var i = 1, _i = n - k + 1; i < _i; i++) {
            var d = r - h[i - 1] + h[i + k - 1];
            if (d < r) {
                t = i;
            }

            if (d === n) {
                return t + 1;
            }

            r = d;
        }

        return t + 1;
    }.apply(null, readline().split(' ').map(Number)));

}.call(this));

;(function () {

    print(function (n, k) {
        var h = readline().split(' ').map(Number),
            r = 0, t = 0;

        for (var i = 0; i < k; i++) {
            r += h[i];
        }

        for (var i = 1, _i = n - k + 1; i < _i; i++) {
            var d = r - h[i - 1] + h[i + k - 1];
            if (d < r) {
                t = i;
            }

            if (d === 1) {
                return t;
            }

            r = d;
        }

        return t + 1;
    }.apply(null, readline().split(' ').map(Number)));

}.call(this));

function main() {
    var line = readline().split(' ').map(Number);
    var n = line[0];
    var k = line[1];
    var data = readline().split(' ').map(Number);
    var sum = 0;
    for(var i=0;i<k-1;i++){
        sum += data[i];
    }
    var min = Number.MAX_VALUE
    var res = 1;
    for(var i=0;i<n-k;i++){
        sum += data[i+k-1];
        if(sum < min){
            min = sum;
            res = i+1;
        }
        sum -= data[i];
    }
    print(res)
}

main()

function main() {
    var line = readline().split(' ').map(Number);
    var n = line[0];
    var k = line[1];
    var data = readline().split(' ').map(Number);
    var sum = 0;
    for(var i=0;i<k-1;i++){
        sum += data[i];
    }
    var min = Number.MAX_VALUE
    var res = -1;
    for(var i=0;i<n-k;i++){
        sum += data[i+k-1];
        if(sum < min){
            min = sum;
            res = i+1;
        }
        sum -= data[i];
    }
    print(res)
}

main()

function main() {
    var line = readline().split(' ').map(Number);
    var n = line[0];
    var k = line[1];
    var data = readline().split(' ').map(Number);
    var sum = 0;
    for(var i=0;i<k-1;i++){
        sum += data[i];
    }
    var min = Number.MAX_VALUE
    var res = 1;
    for(var i=0;i<n-k;i++){
        sum += data[i+k-1];
        print(sum)
        if(sum < min){
            min = sum;
            res = i+1;
        }
        sum -= data[i];
    }
    print(res)
}

main()

var optimalStartPoint = function ( planks, k ) {
  var optimal,
    minSum,
    sum,
    i;

   minSum = 0;
   sum = 0;
   optimal = 0;
   for ( i = 0; i < k; ++i ) {
     minSum += planks[ i ];
   }

   for ( i = 1; i < planks.length - k + 1; ++i ) {
     sum = minSum - planks[ i - 1 ] + ( planks[ i + k - 1 ] || 0 );
     if ( sum < minSum ) {
       minSum = sum;
       optimal = i;
     }
   }
   return optimal;
};

var input = readline().split( " " ).map( i => parseInt( i, 10 ) );
var k = input[ 1 ];
var planks = readline().split( " " ).map( hi => parseInt( hi, 10 ) );
print( optimalStartPoint( planks, k ) + 1 );

var optimalStartPoint = function ( planks, k ) {
  var optimal,
    minSum,
    sum,
    i;

   minSum = 0;
   sum = 0;
   optimal = 0;
   for ( i = 0; i < k; ++i ) {
     minSum += planks[ i ];
   }

   for ( i = 1; i < planks.length - k + 1; ++i ) {
     sum = sum - planks[ i - 1 ] + planks[ i + k - 1 ];
     if ( sum < minSum ) {
       minSum = sum;
       optimal = i;
     }
   }
   return optimal;
};

var input = readline().split( " " ).map( i => parseInt( i, 10 ) );
var k = input[ 1 ];
var planks = readline().split( " " ).map( hi => parseInt( hi, 10 ) );
print( optimalStartPoint( planks, k ) + 1 );


let input = ''

process.stdin.on('data', (x) => input += x)

process.stdin.on('end', () => {
  const lines = input.trim().split('\n')
  const T = parseInt(lines[0])
  let curLine = 1
  for (let t = 0; t < T; t++) {
    const [n] = lines[curLine++].split(' ').map((x) => parseInt(x))
    for (let r = 0; r < n; r++) {
      console.log(lines[curLine++].split(' ').map((x, c) => parseInt(x) + (r + c + parseInt(x)) % 2).join(' '))
    }
  }
})

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

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

function main() {
  let t = +readLine();
  while (t--) {
    const [rowLen, colLen] = readLine().split(" ").map(Number);
    const arr = [];
    let i = 0;
    while (i++ < rowLen) {
      const row = readLine().split(" ").map(Number);
      arr.push(row);
    }
    for (let row = 0; row < rowLen; row++) {
      for (let col = 0; col < colLen; col++) {
        if ((row + col) % 2 === 0) {
          if (arr[row][col] % 2 === 1) arr[row][col]++;
        } else {
          if (arr[row][col] % 2 === 0) arr[row][col]++;
        }
      }
    }
    for (let row = 0; row < rowLen; row++) console.log(arr[row].join(" "));
  }
}

let input = ''

process.stdin.on('data', (x) => input += x)

process.stdin.on('end', () => {
  const lines = input.trim().split('\n')
  const T = parseInt(lines[0])
  let curLine = 1
  for (let t = 0; t < T; t++) {
    const [n, m] = lines[curLine++].split(' ').map((x) => parseInt(x))
    const mat = new Array(n)
    const cells = []
    for (let r = 0; r < n; r++) {
      mat[r] = lines[curLine++].split(' ').map((x) => parseInt(x))
      for (let c = 0; c < m; c++) {
        cells.push([r, c])
      }
    }
    cells.sort(([ra, ca], [rb, cb]) => mat[ra][ca] - mat[rb][cb])
    cells.forEach(([r, c]) => {
      const delta = [[1, 0], [-1, 0], [0, 1], [0, -1]]
      let change = false
      delta.forEach(([dr, dc]) => {
        const nr = r + dr
        const nc = c + dc

        if (nr < 0 || nr >= n || nc < 0 || nc >= m) {
          return
        }

        if (mat[nr][nc] === mat[r][c]) {
          change = true
        }
      })

      if (change) {
        mat[r][c]++
      }
    })

    for (let r = 0; r < n; r++) {
      console.log(mat[r].join(' '))
    }
  }
})

let input = ''

process.stdin.on('data', (x) => input += x)

process.stdin.on('end', () => {
  const lines = input.trim().split('\n')
  const T = parseInt(lines[0])
  let curLine = 1
  for (let t = 0; t < T; t++) {
    const [n, m] = lines[curLine++].split(' ').map((x) => parseInt(x))
    const mat = new Array(n)
    const cells = []
    for (let r = 0; r < n; r++) {
      mat[r] = lines[curLine++].split(' ').map((x) => parseInt(x))
      for (let c = 0; c < m; c++) {
        cells.push([r, c])
      }
    }
    cells.sort(([ra, ca], [rb, cb]) => mat[ra][ca] - mat[rb][cb])
    for (let rem = 0; rem < 2; rem++) {
      cells.forEach(([r, c]) => {
        if ((r + c) % 2 !== rem) {
          return
        }

        const delta = [[1, 0], [-1, 0], [0, 1], [0, -1]]
        let change = false
        delta.forEach(([dr, dc]) => {
          const nr = r + dr
          const nc = c + dc

          if (nr < 0 || nr >= n || nc < 0 || nc >= m) {
            return
          }

          if (mat[nr][nc] === mat[r][c]) {
            change = true
          }
        })

        if (change) {
          mat[r][c]++
        }
      })
    }

    for (let r = 0; r < n; r++) {
      console.log(mat[r].join(' '))
    }
  }
})


'use strict'

let inp = readline()
let N = +readline()
let lll

let dic = []
while (lll = readline()) {
  dic.push(lll)
}

print(dic.filter(w => w.startsWith(inp)).sort()[0] || inp)

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

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

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

function main() {
	var prefix = trim(readline());

	var numCandidates = parseInt(readline(), 10),
		candidates = new Array(numCandidates);
	for (var candidateIndex = 0; candidateIndex < numCandidates; ++candidateIndex) {
		candidates[candidateIndex] = trim(readline());
	}

	candidates.sort();

	var regex = new RegExp("^"+prefix);

	for (var candidateIndex = 0; candidateIndex < numCandidates; ++candidateIndex) {
		if (regex.test(candidates[candidateIndex])) {
			print(candidates[candidateIndex]);
			return;
		}
	}

	print(prefix);
}

main();

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

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

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

function main() {
	var prefix = trim(readline());

	var numCandidates = parseInt(readline(), 10),
		candidates = new Array(numCandidates);
	for (var candidateIndex = 0; candidateIndex < numCandidates; ++candidateIndex) {
		candidates[candidateIndex] = trim(readline());
	}

	candidates.sort();

	var regex = new RegExp("^"+prefix);

	for (var candidateIndex = 0; candidateIndex < numCandidates; ++candidateIndex) {
		if (candidates[candidateIndex].match(regex)) {
			print(candidates[candidateIndex]);
			return;
		}
	}

	print(prefix);
}

main();

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

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

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

function main() {
	var prefix = trim(readline()),
		prefixLength = prefix.length;

	var numCandidates = parseInt(readline(), 10),
		candidates = new Array(numCandidates);
	for (var candidateIndex = 0; candidateIndex < numCandidates; ++candidateIndex) {
		candidates[candidateIndex] = trim(readline());
	}

	candidates.sort();

	for (var candidateIndex = 0; candidateIndex < numCandidates; ++candidateIndex) {
		if (candidates[candidateIndex].substring(0, prefixLength) == prefix) {
			print(candidates[candidateIndex]);
			return;
		}
	}

	print(prefix);
}

main();

var input = readline();
var check = new RegExp('^' + input);
var iteration = readline();

var result;

for (var i = 0; i < iteration; i++) {
	var currentInput = readline();
	//currentInput.match(check)&& result?(( currentInput < result)&&result = currentInput):	result = currentInput
	if (currentInput.match(check)) {

result? (currentInput < result?	result = currentInput:result):(result = currentInput)
	}

}

!!result? print(result):print(input)

var word = readline();
var re = new RegExp('^' + word);
var n = parseInt(readline());
var res;
for (var i = 0; i < n; i++) {
	var input = readline();
	if (input.match(re)) {
		if (res) {
			if (input < res) {
				res = input;
			}
		} else {
			res = input;
		}
	}
}

if (res) {
	print(res);
} else {
	print(word);
}

var input = readline();
var iteration = readline();
var check = new RegExp('^' + input);

var result;

for (var i = 0; i < iteration; i++) {
	var currentInput = readline();
	currentInput.match(check)&& result? (currentInput < result? result = currentInput : result) : (result = currentInput)
}
!!result? print(result):print(input)

var input = readline();
var iteration = readline();
var check = new RegExp('^' + input);

var result;

for (var i = 0; i < iteration; i++) {
	var currentInput = readline();
	currentInput.match(check)&& result? (currentInput < result? (result = currentInput) : result) : (result = currentInput)
}
!!result? print(result):print(input)


var x=parseInt(readline());
var arr=readline().split(' ').map(a => parseInt(a));

arr.sort((a,b) => a-b);

for(var i=arr.length-1; i>=0; i--){
  var sqrt= Math.floor(Math.sqrt(arr[i]));
  if(sqrt*sqrt !== arr[i]){
    print(arr[i]);
    break;
  }else
    continue;
}

n=parseInt(readline());
mas=readline().split(' ');
function compareNumeric(a, b) {
  if (a > b) return 1;
  if (a < b) return -1;
}
for(i=0;i<n; i++) {
    mas[i] = parseInt(mas[i]);
}
mas.sort(compareNumeric).reverse();
for(i=0;i<n; i++) {
    if(Math.sqrt(mas[i])%1 !== 0) {
        print(mas[i]);
        break;
    }
}

var x = readline();
var nums = readline().split(' ').map(x => Number.parseInt(x));

function isPerfect(x){
    var comp = Math.sqrt(x).toFixed(0)

    return x == comp * comp;
}
var max = -Infinity;
for(var i = 0; i < nums.length; i++){
    if(!isPerfect(nums[i])){
        max = Math.max(max, nums[i]);
    }
}

print(max);

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

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

  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => b - a);

  for (let i = 0; i < arr.length; i++) {
    if (!Number.isInteger(Math.sqrt(arr[i]))) {
      console.log(arr[i]);
      break;
    }
  }

  c++;
});

var x=parseInt(readline());
var arr=readline().split(' ').map(a => parseInt(a));

arr.sort((a,b) => a-b);

for(var i=arr.length-1; i>=0; i--){
  var sqrt= Math.sqrt(arr[i]);
  if(sqrt*sqrt !== arr[i]){
    print(arr[i]);
    break;
  }else
    continue;
}

n=parseInt(readline());
mas=readline().split('');
function compareNumeric(a, b) {
  if (a > b) return 1;
  if (a < b) return -1;
}
for(i=0;i<mas.length; i++) {
    mas[i] = parseInt(mas[i]);
}
mas.sort(compareNumeric).reverse();
for(i=0;i<mas.length; i++) {
    if(Math.sqrt(mas[i])%1 !== 0) {
        print(mas[i]);
        break;
    }
}


var
    num      = parseInt(readline()),
    arr      = readline().split(" ")
;

for(var i in arr) {
    arr[i] = parseInt(arr[i]);
}

var sort = arr.slice(0);
sort.sort(function(a, b){if(a==b) return 0; return a > b ? 1 : -1})
sort.reverse()

for(var i in arr){
    if (sort[0] == arr[i]) {
        print((i - 1 + 2) + " " + sort[1])
        break;
    }
}

readline();
var index;
var max = 0;
var max2 = 0;
readline().split(' ').map(function(v){
	return +v;
}).forEach(function(v, i){
	if(v>max){
		max2 = max;
		max = v;
		index = i;
	}else if(v>max2){
		max2 = v;
	}
});
print(index+1, max2);

'use strict';

/*let input = `2
5 7`.split('\n');
function print(output) {
	console.log(output);
}
function readline() {
	return input.shift();
}*/

//code

var n = Number(readline());
var prices = readline().split(' ').map(function (el, i) {
	return { index: i, val: Number(el) };
});
prices.sort(function (a, b) {
	return a.val - b.val;
});
print(prices.pop().index + 1 + " " + prices.pop().val);

readline();
var a=readline().split(" "),b=a.slice().sort(function(a,b){return +a-b}),l=b.length;print(a.indexOf(b[l-1])+1+" "+b[l-2]);

var n = Number(readline());
var inp = readline().split(' ').map(cur => Number(cur));
var max = Math.max(...inp);
var index = inp.indexOf(max)
inp.splice(index, 1);
var res = [index + 1, Math.max(...inp)];
print(res.join(' '));

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

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

  const arr = d.split(' ').map(Number);
  const sortedArr = arr.slice();
  sortedArr.sort((a, b) => a - b);
  const max = sortedArr[sortedArr.length - 1];
  const secondMax = sortedArr[sortedArr.length - 2];
  let maxIdx;

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === max) {
      maxIdx = i + 1;
      break;
    }
  }

  console.log(maxIdx, secondMax);

  c++;
});

var
    num = readline(),
    arr = readline().split(" "),
    maxx = 0,
    index = 0
;

var max = Math.max.apply(Math, arr);

for(var i in arr){
    if (arr[i] < max && arr[i] > maxx) {
        maxx = arr[i];

    }
    if (max == arr[i]) index = parseInt(i) + 1;
}

print(index + " " + maxx)


var input = readline().split(' ').map(function(x){return Number(x)});
var a = input[0];
var b = input[1];
var s1 = readline();
var s2 = readline();
var min = 100000;
var res = [];
for(var i = 0 ; i <= (s2.length - s1.length) ; i++){
    var ss = s2.substring(i, i + s1.length);
    var tmp = [];
    var act = 0;
    for(var j = 0 ; j < s1.length ; j++){
        if( s1[j] !== ss[j] ){
            act++; tmp.push(j + 1);
        }
    }
    if(act < min){
        min = act;
        res = tmp;
    }
}

print(min);
for(var i = 0 ; i < res.length ; i ++)write(res[i] + " ");

var st = readline().split(' ').map(Number);
var s = readline();
var t = readline();
var sl = st[0];
var tl = st[1];
var ans = 1100;
var pos = [];
for (var i=0; i<=tl-sl; i++){
	var count = 0;
	var poscount = [];
	for (var j=0; j<sl; j++){
		if (s[j] != t[i+j]){
			count++;
			poscount.push(j+1);
		}
	}
	if (count < ans){
		ans = count;
		pos = poscount;
	}
}
print(ans);
print(pos.join(' '));


var n = +readline();
var arr=[];
for(var i=0;i<n;i++)
    arr.push(readline().split(" ").map(v=>+v));
arr.sort((a,b)=>{
    if(a[0]===b[0])
        return a[1]-b[1];
    return a[0]-b[0];
});

var prev=0;
for(var i=0;i<n;i++){
    var t=arr[i][1]<prev?0:1;
    prev=arr[i][t];
}
print(prev);

var n = parseInt(readline());
var a = new Array();
for(var i=0; i<n; i++)
{
   var nums = readline().split(' ');
   var obj = new Object();
   obj.x = parseInt(nums[0]);
   obj.y = parseInt(nums[1]);
   a.push(obj);
}
a.sort(sortObj);

var ans = 0;

for(var i=0; i<n; i++)
{
    if(a[i].y>=ans)
	{
	    ans=a[i].y;
	}
	else
	{
	    ans=a[i].x;
	}
}
print(ans);

function sortObj(ojA, ojB)
{
    if(ojA.x==ojB.x)
	{
	    return ojA.y-ojB.y;
	}
	else
	{
	    return ojA.x - ojB.x;
	}
}

var node = function(x) {
    this.a=x[0];
    this.b=x[1];
}

var by_node = function(x,y){
    if(x.a!=y.a) return x.a<y.a;
    return x.b<y.b;
}

var merge = function(l,r,cmp){
    if(!l) l=[];
    if(!r) r=[];
    var ans=[];
    var sl=0;
    var sr=0;
    while(sl<l.length && sr<r.length){
        if(cmp(l[sl],r[sr])) ans.push(l[sl++]);
        else ans.push(r[sr++]);
    }
    if(sl==l.length) while(sr<r.length) ans.push(r[sr++]);
    if(sr==r.length) while(sl<l.length) ans.push(l[sl++]);
    //print("-M:"+ans.length+"->"+l.length+" + "+r.length);
    return ans;
}

var merge_sort = function(arr,cmp) {
    if(!arr) return arr;
    if(arr.length<2) return arr;
    var mid = Math.floor(arr.length/2);
    var right=[];
    for(var i=mid;i<arr.length;i++) right.push(arr[i]);
    var left = arr.splice(0,mid);

    //print("Sort-----------------------");
    //print("arr   length : "+arr.length);
    //print("left  length : "+left.length);
    //print("right length : "+right.length);
    //print("ans   length : "+ans.length);

    var l=merge_sort(left,cmp);
    var r=merge_sort(right,cmp);
    return merge(l,r,cmp);
}

var main = function(){
    var line=readline().split(' ');
    var n=parseInt(line);
    var arr = [];
    for(var i=0;i<n;i++) {
        line=readline();
        arr[i] = new node(line.split(' ').map(function(x){return parseInt(x);}));
    }
    //print("arr length = "+arr.length);
    var sarr=merge_sort(arr,by_node);
    //print("sarr length = "+sarr.length);
    //sarr.forEach(function(x){print(x.a+" "+x.b);});
    var ans=sarr[0].b;
    sarr.forEach(function(x){
        if(x.b>=ans) ans=x.b;
        else ans=x.a;
    })
    print(ans);
}

main();

var intp = function(x){
	return parseInt(x);
}

var node = function(x){
	this.a=parseInt(x[0]);
	this.b=parseInt(x[1]);
}

var by_node = function(x,y){
	return x.a!=y.a?x.a>y.a:x.b>y.b;
}

var out_type = function(x){
	print(typeof(x.a)+" "+typeof(x.b));
}

var out_value = function(x){
	print(x.a+" "+x.b);
}

var qsort = function(arr,cmp)
{
	if(!arr) return [];
	if(arr.length<=1) return arr;
	var p=Math.floor(Math.random()*arr.length);
	var pv=arr[p];
	arr[p]=arr[arr.length-1];
	arr.length--;
	var l=arr.filter(function(value){return cmp(pv,value);});
	var r=arr.filter(function(value){return !cmp(pv,value);});
	return qsort(l,cmp).concat([pv],qsort(r,cmp));
}

var line;
while(line=readline()) {
	var n = line.split(' ').map(intp)[0];
	var arr = [];
	for(var i=0;i<n;i++) {
		line=readline();
		arr[i] = new node(line.split(' '));
	}
	sarr=qsort(arr,by_node);
	var ans=sarr[0].b;
	sarr.forEach(function(x){
		if(x.b>=ans) ans=x.b;
		else ans=x.a;
	});
	print(ans);
}

var node = function(x){
    this.a=x[0];
    this.b=x[1];
}

var by_node = function(x,y){
    if(x.a!=y.a) return x.a-y.a;
    return x.b-y.b;
}

var out_value = function(x){
    print(x.a+" "+x.b);
}

while(true) {
    line = readline();
    if(!line) break;
    n = parseInt(line);
    var arr = new Array(n+5);
    for(var i=0;i<n;i++) {
        line = readline();
        var numbers = line.split(' ').map(function(x){return parseInt(x);});
        arr[i] = new node(numbers);
    }
    arr.sort(by_node);
    var ans=arr[0].b;
    arr.forEach(function(x){
        if(x.b>=ans) ans=x.b;
        else ans=x.a;
    });
    print(ans);
}

var arr = [], elements;
var queries = parseInt(readline())
for (var l = 0; l < queries;l++){
	elements = readline().split(' ').map((val)=>{
		return parseInt(val);
	})
	arr.push(elements);
}
arr.sort((a,b)=>{
	if (a[0] == b[0]){
		return a[1] - b[1];
	}
	else{
	return a[0] - b[0];
	}
})
var enDay = Math.min(arr[0][0], arr[0][1])
var interim;
for (var k = 1; k<arr.length; k++){
	interim = Math.min(arr[k][0],arr[k][1])
	if (interim >= enDay){
		enDay = interim;
	}
	else{
		enDay = (interim == arr[k][0]) ? arr[k][1] : arr[k][0];
	}
}
print(enDay)

var n = parseInt(readline());
var a= [];
for (var i=0;i<n;i++) {a.push(readline().split(' ').map(Number))}
var p =a.sort((a, b)=>{ if ((a[0]-b[0])!==0) {return a[0]-b[0]} else {return a[1]-b[1]}}).map(function (xs) {var mi= Math.min.apply(null,xs); var ma = Math.max.apply(null,xs);if (mi>=this.t) {this.t=mi; return mi} else {this.t=ma; return ma}},{t:0}).pop();
print (p);

n = readline().split(' ').map(function(x){return parseInt(x);})[0];

var arr=[];

for(var i=0;i<n;i++) {
    var numbers = readline().split(' ').map(function(x){return parseInt(x)});
    arr[i]={a:numbers[0], b:numbers[1]};
}

arr.sort(function(x,y){
    if(x.a!=y.a) return x.a>y.a;
    else return x.b>y.b;
})

var ans=arr[0].b;

for(var i=0;i<n;i++) {
    if(arr[i].b>=ans) ans=arr[i].b;
    else ans=arr[i].a;
}

print(ans);

n = parseInt(readline());

var arr=[];

for(var i=0;i<n;i++) {
    var numbers = readline().split(' ').map(function(x){return parseInt(x)});
    arr[i]={a:numbers[0], b:numbers[1]};
}

arr.sort(function(x,y){
    if(x.a!=y.a) return x.a>y.a;
    else return x.b>y.b;
})

var ans=arr[0].b;

for(var i=0;i<n;i++) {
    if(arr[i].b>=ans) ans=arr[i].b;
    else ans=arr[i].a;
}

print(ans);

n = parseInt(readline());

var arr=[];

for(var i=0;i<n;i++) {
    var numbers = readline().split(' ').map(function(x){return parseInt(x)});
    arr.push({a:numbers[0], b:numbers[1]});
}

arr.sort(function(x,y){
    if(x.a!=y.a) return x.a>y.a;
    else return x.b>y.b;
})

var ans=arr[0].b;

for(var i=0;i<n;i++) {
    if(arr[i].b>=ans) ans=arr[i].b;
    else ans=arr[i].a;
}

print(ans);

n = parseInt(readline());

var arr=[];

for(var i=0;i<n;i++) {
    var numbers = readline().split(' ').map(function(x){return parseInt(x)});
    arr.push({a:numbers[0], b:numbers[1]});
}

arr.sort(function(x,y){
    if(x.a!=y.a) return x.a>y.a;
    else return x.b>y.b;
})

var ans=arr[0].b;

arr.forEach(function(x){
    if(x.b>=ans) ans=x.b;
    else ans=x.a;
})

print(ans);

var arr = [], elements = []
var queries = parseInt(readline())
for (var l = 0; l < queries;l++){
	readline().split(' ').map((val)=>{
		elements.push(parseInt(val));
	})
	arr.push(elements);
}
arr.sort((a,b)=>{
	return a[0] - b[0]
})
var enDay = Math.min(arr[0][0], arr[0][1])
var interim;
for (var k = 1; k<arr.length; k++){
	interim = Math.min(arr[k][0],arr[k][1])
	if (interim >= enDay){
		enDay = interim;
	}
	else{
		enDay = (interim == arr[k][0]) ? arr[k][1] : arr[k][0];
	}
}
print(enDay)

var arr = [], elements = []
var queries = parseInt(readline())
for (var l = 0; l < queries;l++){
	readline().split(' ').map((val)=>{
		elements.push(parseInt(val));
	})
	arr.push(elements);
	elements.pop();
	elements.pop()
}
arr.sort((a,b)=>{
	return a[0] - b[0]
})
var enDay = Math.min(arr[0][0], arr[0][1])
var interim;
for (var k = 1; k<arr.length; k++){
	interim = Math.min(arr[k][0],arr[k][1])
	if (interim >= enDay){
		enDay = interim;
	}
	else{
		enDay = (interim == arr[k][0]) ? arr[k][1] : arr[k][0];
	}
}
print(enDay)

var arr = [], elements;
var queries = parseInt(readline())
for (var l = 0; l < queries;l++){
	elements = readline().split(' ').map((val)=>{
		return parseInt(val);
	})
	arr.push(elements);
}
arr.sort((a,b)=>{
	return a[0] - b[0]
})
var enDay = Math.min(arr[0][0], arr[0][1])
var interim;
for (var k = 1; k<arr.length; k++){
	interim = Math.min(arr[k][0],arr[k][1])
	if (interim >= enDay){
		enDay = interim;
	}
	else{
		enDay = (interim == arr[k][0]) ? arr[k][1] : arr[k][0];
	}
}
print(enDay)

var n = +readline();
var arr=[];
for(var i=0;i<n;i++)
    arr.push(readline().split(" ").map(v=>+v));
for(var i=0;i<n;i++)
    print(arr[i]);
arr.sort((a,b)=>{
    if(a[0]===b[0])
        return a[1]-b[1];
    return a[0]-b[0];
});

var ans=0;
var prev=0;
for(var i=0;i<n;i++){
    var t=arr[i][1]<prev;
    ans=arr[i][t];
    prev=arr[i][t];
}
print(ans);

var n = +readline();
var arr=[];
for(var i=0;i<n;i++)
    arr.push(readline().split(" ").map(v=>+v));
print(arr);
arr.sort((a,b)=>{
    if(a[0]===b[0])
        return a[1]-b[1];
    return a[0]-b[0];
});

var ans=0;
var prev=0;
for(var i=0;i<n;i++){
    var t=arr[i][1]<prev;
    ans=arr[i][t];
    prev=arr[i][t];
}
print(ans);

var n = +readline();
var arr=[];
for(var i=0;i<n;i++)
    arr.push(readline().split(" ").map(v=>+v));
arr.sort((a,b)=>{
    if(a[0]===b[0])
        return a[1]-b[1];
    return a[0]-b[0];
});

for(var i=0;i<n;i++)
    print(arr[i]);
var ans=0;
var prev=0;
for(var i=0;i<n;i++){
    var t=arr[i][1]<prev?0:1;
    ans=arr[i][t];
    prev=arr[i][t];
}
print(ans);

var n = +readline();
var arr=[];
for(var i=0;i<n;i++)
    arr.push(readline().split(" ").map(v=>+v));
arr.sort((a,b)=>{
    if(a[0]===b[0])
        return a[1]-b[1];
    return a[0]-b[0];
});

var ans=0;
var prev=0;
for(var i=0;i<n;i++){
    var t=arr[i][1]<prev;
    ans=arr[i][t];
    prev=arr[i][t];
}
print(ans);


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

const calculate = (chainNumberList, cList, aList, bList) => {
  if (chainNumberList === 1) return 0

  let currentCycleLength = 0
  let maxCycleLength = 0

  for (let index = 1; index < chainNumberList; index++) {
    const a = aList[index]
    const b = bList[index]

    if (index === 1) {
      currentCycleLength = Math.abs(a - b)
    } else {
      const baseLength = Math.abs(a - b)
      const partLength = cList[index - 1] - 1 - baseLength
      if (baseLength > partLength + currentCycleLength) {
        currentCycleLength = baseLength
      } else {
        currentCycleLength += partLength
      }
    }

    if (a === b) {
      currentCycleLength = 0
    }

    currentCycleLength += 2

    if (maxCycleLength < cList[index] + currentCycleLength) {
      maxCycleLength = cList[index] - 1 + currentCycleLength
    }
  }

  currentCycleLength += cList[cList.length - 1] - 1

  if (maxCycleLength < currentCycleLength) {
    maxCycleLength = currentCycleLength
  }

  return maxCycleLength
}

let index = -1
let maxRound = 0
let round = 0

let cList, aList, bList, chainNumberList
let answer = []

readline.on('line', line => {
  if (index === -1) {
    maxRound = Number(line)
    index = 0
  } else {
    const mode = index % 4
    if (mode === 0) {
      chainNumberList = Number(line)
    } else if (mode === 1) {
      cList = line.split(' ').map(val => Number(val))
    } else if (mode === 2) {
      aList = line.split(' ').map(val => Number(val))
    } else if (mode === 3) {
      bList = line.split(' ').map(val => Number(val))
      answer.push(calculate(chainNumberList, cList, aList, bList))
      round++
      if (round === maxRound) {
        readline.close()
        console.log(answer.join('\n'))
        return
      }
    }
    index++
  }
})

// chainNumberList, cList, aList, bList
// console.log(calculate(4, [3, 4, 3, 3], [-1, 1, 2, 2], [-1, 2, 2, 3]))

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

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

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

		let ans = 0;
		let cur = Math.abs(a[1] - b[1]);
		for (let i = 1; i < n; i++) {
			cur += 2;
			ans = Math.max(ans, cur + c[i] - 1);
			if (a[i+1] == b[i+1]) {
				cur = 0;
			} else {
				cur += Math.min(a[i+1], b[i+1]) - 1
				cur += c[i] - Math.max(a[i+1], b[i+1]);
				cur = Math.max(cur, Math.abs(a[i+1] - b[i+1]));
			}
		}

		console.log(ans);
	}
}

'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() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        var map = {}
        var c = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var b = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        var currentLength = 0
        var len = 0
        var max = 0
        for (let i = 1; i < n; i++) {
            currentLength = 1+c[i]+Math.abs(a[i]-b[i])
            if (a[i] !== b[i]) {
                currentLength = Math.max(currentLength, len + c[i]-Math.abs(a[i]-b[i])+1)
            }
            max = Math.max(max, currentLength)
            len = currentLength
            // console.log(currentLength, a[i], b[i], c[i - 1])
        }
        console.log(max)
    })
}

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

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

const INF = 1e9+5;

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

		let ans = 0;
		for (let i = 1, cur = -INF; i < n; i++) {
			if (a[i] == b[i]) {
				cur = 0;
			} else {
				cur += c[i-1] - 1 - Math.abs(a[i] - b[i]);
				cur = Math.max(cur, Math.abs(a[i] - b[i]));
			}
			cur += 2;
			ans = Math.max(ans, cur + c[i] - 1);
		}

		console.log(ans);
	}
}

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

const calculate = (chainNumberList, cList, aList, bList) => {
  if (chainNumberList === 1) return 0

  let maxCycleLength = 0
  let currentCycleLength = 0
  for (let index = 1; index < chainNumberList; index++) {
    const a = aList[index]
    const b = bList[index]
    const cOld = cList[index - 1]

    if (index === 1) {
      currentCycleLength += Math.abs(b - a)
    } else {
      currentCycleLength += cOld - 1 - Math.abs(b - a)
    }

    if (a === b) {
      if (maxCycleLength < currentCycleLength) {
        maxCycleLength = currentCycleLength
        currentCycleLength = 0
      }
    } else {
      const newCurrentCycleLength = currentCycleLength + cOld - 1
      if (maxCycleLength < newCurrentCycleLength) {
        maxCycleLength = newCurrentCycleLength
      }
    }
    currentCycleLength += 2
  }

  currentCycleLength += cList[cList.length - 1] - 1

  if (maxCycleLength < currentCycleLength) {
    maxCycleLength = currentCycleLength
  }

  return maxCycleLength
}

let index = -1
let maxRound = 0
let round = 0

let cList, aList, bList, chainNumberList
let answer = []

readline.on('line', line => {
  if (index === -1) {
    maxRound = Number(line)
    index = 0
  } else {
    const mode = index % 4
    if (mode === 0) {
      chainNumberList = Number(line)
    } else if (mode === 1) {
      cList = line.split(' ').map(val => Number(val))
    } else if (mode === 2) {
      aList = line.split(' ').map(val => Number(val))
    } else if (mode === 3) {
      bList = line.split(' ').map(val => Number(val))
      answer.push(calculate(chainNumberList, cList, aList, bList))
      round++
      if (round === maxRound) {
        readline.close()
        console.log(answer.join('\n'))
        return
      }
    }
    index++
  }
})

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

const calculate = (chainNumberList, cList, aList, bList) => {
  let maxCycleLength = 0
  let currentCycleLength = 0
  for (let index = 1; index < chainNumberList; index++) {
    const a = aList[index]
    const b = bList[index]
    const cOld = cList[index - 1]

    if (index === 1) {
      currentCycleLength += Math.abs(b - a)
    } else {
      currentCycleLength += cOld - 1 - Math.abs(b - a)
    }

    if (a === b) {
      if (maxCycleLength < currentCycleLength) {
        maxCycleLength = currentCycleLength
        currentCycleLength = 0
      }
    } else {
      const newCurrentCycleLength = currentCycleLength + cOld - 1
      if (maxCycleLength < newCurrentCycleLength) {
        maxCycleLength = newCurrentCycleLength
      }
    }
    currentCycleLength += 2
  }

  currentCycleLength += cList[cList.length - 1] - 1

  if (maxCycleLength < currentCycleLength) {
    maxCycleLength = currentCycleLength
  }

  return maxCycleLength
}

let index = -1
let maxRound = 0
let round = 0

let cList, aList, bList, chainNumberList
let answer = []

readline.on('line', line => {
  if (index === -1) {
    maxRound = Number(line)
    index = 0
  } else {
    const mode = index % 4
    if (mode === 0) {
      chainNumberList = Number(line)
    } else if (mode === 1) {
      cList = line.split(' ').map(val => Number(val))
    } else if (mode === 2) {
      aList = line.split(' ').map(val => Number(val))
    } else if (mode === 3) {
      bList = line.split(' ').map(val => Number(val))
      answer.push(calculate(chainNumberList, cList, aList, bList))
      round++
      if (round === maxRound) {
        readline.close()
        console.log(answer.join('\n'))
        return
      }
    }
    index++
  }
})

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

const calculate = (chainNumberList, cList, aList, bList) => {
  let maxCycleLength = 0
  let currentCycleLength = 0
  for (let index = 1; index < chainNumberList; index++) {
    const a = aList[index]
    const b = bList[index]
    const cOld = cList[index - 1]

    if (index === 1) {
      currentCycleLength += Math.abs(b - a)
    } else {
      currentCycleLength += cOld - 1 - Math.abs(b - a)
    }

    if (a === b) {
      if (maxCycleLength < currentCycleLength) {
        maxCycleLength = currentCycleLength
        currentCycleLength = 0
      }
    }
    currentCycleLength += 2
  }

  currentCycleLength += cList[cList.length - 1] - 1

  if (maxCycleLength < currentCycleLength) {
    maxCycleLength = currentCycleLength
  }

  return maxCycleLength
}

let index = -1
let maxRound = 0
let round = 0

let cList, aList, bList, chainNumberList
let answer = []

readline.on('line', line => {
  if (index === -1) {
    maxRound = Number(line)
    index = 0
  } else {
    const mode = index % 4
    if (mode === 0) {
      chainNumberList = Number(line)
    } else if (mode === 1) {
      cList = line.split(' ').map(val => Number(val))
    } else if (mode === 2) {
      aList = line.split(' ').map(val => Number(val))
    } else if (mode === 3) {
      bList = line.split(' ').map(val => Number(val))
      answer.push(calculate(chainNumberList, cList, aList, bList))
      round++
      if (round === maxRound) {
        readline.close()
        console.log(answer.join('\n'))
        return
      }
    }
    index++
  }
})

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

const calculate = (chainNumberList, cList, aList, bList) => {
  let maxCycleLength = 0
  let currentCycleLength = 0
  for (let index = 1; index < chainNumberList; index++) {
    const a = aList[index]
    const b = bList[index]
    const cOld = cList[index - 1]

    if (index === 1) {
      currentCycleLength += Math.abs(b - a)
    } else {
      currentCycleLength += cOld - 1 - Math.abs(b - a)
    }

    if (a === b) {
      if (maxCycleLength < currentCycleLength) {
        maxCycleLength = currentCycleLength
        currentCycleLength = 0
      }
    }
    currentCycleLength += 2
  }

  currentCycleLength += cList[cList.length - 1] - 1

  if (maxCycleLength < currentCycleLength) {
    maxCycleLength = currentCycleLength
  }

  return maxCycleLength
}

let index = -1
let maxRound = 0
let round = 0

let cList, aList, bList, chainNumberList

readline.on('line', line => {
  if (index === -1) {
    maxRound = Number(line)
    index = 0
  } else {
    const mode = index % 4
    if (mode === 0) {
      chainNumberList = Number(line)
    } else if (mode === 1) {
      cList = line.split(' ').map(val => Number(val))
    } else if (mode === 2) {
      aList = line.split(' ').map(val => Number(val))
    } else if (mode === 3) {
      bList = line.split(' ').map(val => Number(val))
      console.log(calculate(chainNumberList, cList, aList, bList))
      round++
      if (round === maxRound) {
        readline.close()
        return
      }
    }
    index++
  }
})

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

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

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

		let ans = 0;
		for (let i = 1, cur = 0; i < n; i++) {
			if (a[i] == b[i]) {
				cur = 0;
			} else {
				cur += c[i-1] - 1 - Math.abs(a[i] - b[i]);
				cur = Math.max(cur, Math.abs(a[i] - b[i]));
			}
			cur += 2;
			ans = Math.max(ans, cur + c[i] - 1);
		}

		console.log(ans);
	}
}

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

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

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

		let ans = 0;
		let cur = Math.abs(a[1] - b[1]);
		for (let i = 1; i < n; i++) {
			cur += 2;
			ans = Math.max(ans, cur + c[i] - 1);
			if (a[i+1] == b[i+1]) {
				cur = 0;
			} else {
				cur += Math.min(a[i+1], b[i+1]) - 1
				cur += c[i] - Math.max(a[i+1], b[i+1]);
			}
		}

		console.log(ans);
	}
}


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

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

let count = -1
let inputArr = []

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

function solve([n, k], set) {
    set.sort((a, b) => a - b)
    let min = Number.MAX_SAFE_INTEGER, prv = -1
    for (let i of set) {
        if (i - 1 != prv) {
            min = prv + 1
            break
        }
        prv = i
    }
    let max = set[n - 1];
    let a = Math.ceil((min + max) / 2)
    let flag = true
    for (let i of set) {
        if (i == a) flag = false
    }
    if (k == 0) flag = false
    if (min + 1 <= max) return n + Number(flag)
    else return n + k
}

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

function main() {
  const x = readline();

  Array(parseInt(x)).fill(1).map((t, iii) => {
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })
    var exist = false
    for (let i = 0; i < n; i++) {
      if (a[i] >= n) exist = true
    }
    if (!exist) return console.log(n + k)
    if (k === 0) return console.log(n)

    var mex = 0
    var max = 0
    for (let i = 0; i <= n; i++) {
      if (a[i] > max) max = a[i]
    }
    for (let i = 0; i <= n; i++) {
      if (!a.includes(i)) {
        mex = i
        break
      }
    }
    if (!a.includes(Math.ceil((mex + max) / 2))) return console.log(n + 1)
    console.log(n)
    // console.log(exist ? n : n + k)
  })
}

function gcd(a, b) {
  if (!b) {
    return a;
  }

  return gcd(b, a % b);
}

function getInt(num){
        return parseInt(num, 10)
    }

var t = parseInt(readline(), 10);
var lines= [];
for(var i = 0; i<t; i++){
    var line1 = readline().split(' ').map(getInt);
    var n = line1[0];
    var k = line1[1];
    var sorted = readline().split(' ').map(getInt).sort(function(a,b){
        return a-b;
    }).filter(function(item, i, arr){
        return !i || arr[i-1] !== item
    });
    var max = sorted[sorted.length - 1];
    var mex = getMex(sorted, max);

    var addition = 0;
    if(mex-max ===  1){
        addition = k;
    }else if(k >= 1){
        var newItem = Math.ceil((max+mex)/2);
        addition = sorted.some( function(item){
            return item === newItem;
        }) ? 0 : 1;

    }
    print(n + addition);
}

function getMex(arr,max){
    var res = 0;

    arr.forEach(function(item){
        if(res === item){
            res = item +1;
        }
    } )
    return res
}

"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, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    arr.sort((a, b) => a - b);
    let mex = Infinity;
    if (arr[0] !== 0) mex = 0;
    for (let i = 1; i < n; i++) {
      if (arr[i - 1] + 1 !== arr[i]) {
        mex = Math.min(mex, arr[i - 1] + 1);
        break;
      }
    }
    if (mex === Infinity) {
      console.log(k + n);
      continue;
    }
    let obj = {};
    for (let i = 0; i < n; i++) obj[arr[i]] = 1;
    let i = 0,
      max = arr[n - 1];
    while (i < k) {
      let j = Math.ceil((mex + max) / 2);
      if (obj[j]) break;
      else {
        arr.push(j);
        obj[j] = 1;
        if (mex === j) {
          while (obj[j]) j++;
          mex = j;
        }
        max = Math.max(j, max);
      }
      i++;
    }
    console.log(Object.keys(obj).length);
  }
};
solve();

///////////////////////////////// pre-define /////////////////////////////////////
const pr = console.log;
///////////////////////////////////////////////////////////////////////////////////

const solve = (n, k, a) => {
    if (k == 0) return pr(n);
    let max = Math.max.apply(Math, a);
    let mex = n;
    for (let i = 0; i < n; i++) {
        if (i != a[i]) {
            mex = i;
            break;
        }
    }
    if (mex > max) return pr(n + k);
    let add = mex + max + 1 >> 1;
    for (let i = 0; i < n; i++) {
        if (add == a[i]) {
            return pr(n);
        }
    }
    pr(n + 1);
};

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

main()

"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, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    arr.sort((a, b) => a - b);
    let mex = Infinity;
    if (arr[0] === 0) mex = 0;
    for (let i = 1; i < n; i++) {
      if (arr[i - 1] + 1 !== arr[i]) {
        mex = Math.min(mex, arr[i - 1] + 1);
        break;
      }
    }
    if (mex === Infinity) mex = arr[n - 1] + 1;
    let obj = {};
    for (let i = 0; i < n; i++) obj[arr[i]] = 1;
    let i = 0,
      max = arr[n - 1];
    while (i < k) {
      let j = Math.ceil((mex + max) / 2);
      if (obj[j]) break;
      else {
        arr.push(j);
        obj[j] = 1;
        if (mex === j) {
          while (obj[j]) j++;
          mex = j;
        }
        max = Math.max(j, max);
      }
      i++;
    }
    let l = {},
      cnt = 0;
    for (let i = 0; i < arr.length; i++) {
      if (!l[arr[i]]) cnt++;
      else l[arr[i]] = 1;
    }
    console.log(cnt);
  }
};
solve();


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

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

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

function main() {
	function string2hash(s) {
		var h = { nonzero: [] },
			alpha = 'abcdefghijklmnopqrstuvwxyz';
		for (var i = 0; i < 26; ++i) {
			h[alpha.charAt(i)] = 0;
		}
		for (var i = 0; i < s.length; ++i) {
			var ch = s.charAt(i);
			if (h[ch] == 0) {
				h.nonzero.push(ch);
			}
			h[ch] += 1;
		}
		return h;
	}
	var source = string2hash(readline()),
		target = string2hash(readline()),
		count = 0;
	for (var i = 0; i < target.nonzero.length; ++i) {
		var ch = target.nonzero[i];
		if (source[ch] == 0) {
			print(-1);
			return;
		}
		count += Math.min(source[ch], target[ch]);
	}
	print(count);
}

main();

print(function(a, b) {
	var c = new Int32Array(256);
	var has = new Int8Array(256);

	for (var i = 0; i < a.length; i++)
		c[a.charCodeAt(i)]++;

	for (var i = 0; i < 256; i++)
		if (c[i] > 0) has[i] = 1;

	var ans = 0;
	for (var i = 0; i < b.length; i++) {
		var clr = b.charCodeAt(i);
		if (has[clr] === 0) return -1;
		if (c[clr] > 0) {
			c[clr]--;
			ans++;
		}
	}
	return ans;
}(readline(), readline()));

print(function(a, b) {
	var c = new Int32Array(1000);
	for (var i = 0; i < a.length; i++)
		c[a.charCodeAt(i)]++;

	var ans = 0;
	for (var i = 0; i < b.length; i++)
		if (c[b.charCodeAt(i)] > 0) {
			c[b.charCodeAt(i)]--;
			ans++;
		}

	return ans == 0 ? -1 : ans;
}(readline(), readline()));

print(function(a, b) {
	var c = new Int8Array(255);
	for (var i = 0; i < a.length; i++)
		c[a.charCodeAt(i)]++;

	var ans = 0;
	for (var i = 0; i < b.length; i++)
		if (c[b.charCodeAt(i)] > 0) {
			c[b.charCodeAt(i)]--;
			ans++;
		}

	return ans == 0 ? -1 : ans;
}(readline(), readline()));

print(function(a, b) {
	var c = new Int32Array(255);
	for (var i = 0; i < a.length; i++)
		c[a.charCodeAt(i)]++;

	var ans = 0;
	for (var i = 0; i < b.length; i++)
		if (c[b.charCodeAt(i)] > 0) {
			c[b.charCodeAt(i)]--;
			ans++;
		}

	return ans == 0 ? -1 : ans;
}(readline(), readline()));


const readline = require('readline')

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

function solve(n, sa, sb) {
    const min = sa.map((x, i) => {
        const j = binarySearch(0, n - 1, p => sb[p] < x) + 1
        return sb[j] - x
    })
    const bar = [0]
    for (let i = 1; i < n; i++) {
        if (sb[i - 1] < sa[i]) {
            bar.push(i)
        }
    }
    bar.push(n)
    // console.log('bar', bar)
    const max = sa.map((x, i) => {
        const j = binarySearch(0, bar.length - 1, p => bar[p] <= i) + 1
        return sb[bar[j] - 1] - x
    })
    return min.join(' ') + '\n' + max.join(' ')
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

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

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

// Finds index where x should be
function lowerBound(x, a) {
    let iMin = 0;
    let iMax = a.length - 1;
    // 1 2 3 4 (1) => 0
    // 1 2 3 4 (2) => 1
    // 1 2 3 4 (3) => 2
    // 1 2 3 4 (4) => 3
    // 1 2 3 4 (5) => 3
    while (iMax - iMin > 0) {
        const iMiddle = Math.floor((iMax + iMin) / 2);

        if (a[iMiddle] >= x) {
            iMax = iMiddle;
        } else {
            // a[iMiddle] < x
            iMin = iMiddle + 1;
        }
    }

    if (x > a[iMin]) {
        return Math.min(iMin + 1, a.length - 1);
    }

    return iMin;
}

// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));

function pickMinIndex(x, b) {
    for (let j = 0; j < b.length; j++) {
        return lowerBound(x, b);
    }
}

function pickMaxIndex(i, a, b) {
    for (let j = i; j < b.length - 1; j++) {
        if (a[j + 1] > b[j]) {
            return j;
        }
    }

    return b.length - 1;
}

// indecies of elements which cannot be moved by -1
function createArrayOfBoulders(a, b) {
    const boulders = [];

    for (let i = 1; i < a.length; i++) {
        if (a[i] > b[i - 1]) {
            boulders.push(i);
        }
    }

    return boulders;
}

function solve(a, b) {
    const min = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMinIndex(x, b);
        min.push(b[j] - x);
    }

    const boulders = createArrayOfBoulders(a, b);
    // console.log(boulders);
    const max = [];
    for (let i = 0; i < a.length; i++) {
        if (boulders.length > 0) {
            let bi = lowerBound(i, boulders);
            let j = boulders[bi];

            if (j < i) {
                j = b.length - 1;
            } else if (j === i) {
                if (bi === boulders.length - 1) {
                    j = b.length - 1;
                } else {
                    j = boulders[bi + 1] - 1;
                }
            } else if (j > i) {
                j = j - 1;
            }

            max.push(b[j] - a[i]);
            // const j = pickMaxIndex(i, a, b);
            // max.push(b[j] - a[i]);
        } else {
            max.push(b[b.length - 1] - a[i]);
        }
    }

    console.log(min.join(' '));
    console.log(max.join(' '));
}

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].split(' ').map(Number);
        const b = data[i + 2].split(' ').map(Number);

        solve(a, b);
    }
});

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

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

// Finds index where x should be
function lowerBound(x, a) {
    let iMin = 0;
    let iMax = a.length - 1;
    // 1 2 3 4 (1) => 0
    // 1 2 3 4 (2) => 1
    // 1 2 3 4 (3) => 2
    // 1 2 3 4 (4) => 3
    // 1 2 3 4 (5) => 3
    while (iMax - iMin > 0) {
        const iMiddle = Math.floor((iMax + iMin) / 2);

        if (a[iMiddle] >= x) {
            iMax = iMiddle;
        } else {
            // a[iMiddle] < x
            iMin = iMiddle + 1;
        }
    }

    if (x > a[iMin]) {
        return Math.min(iMin + 1, a.length - 1);
    }

    return iMin;
}

// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));

function pickMinIndex(x, b) {
    for (let j = 0; j < b.length; j++) {
        return lowerBound(x, b);
    }
}

function pickMaxIndex(i, a, b) {
    for (let j = i; j < b.length - 1; j++) {
        if (a[j + 1] > b[j]) {
            return j;
        }
    }

    return b.length - 1;
}

// indecies of elements which cannot be moved by -1
function createArrayOfBoulders(a, b) {
    const boulders = [];

    for (let i = 1; i < a.length; i++) {
        if (a[i] > b[i - 1]) {
            boulders.push(i);
        }
    }

    return boulders;
}

function solve(a, b) {
    const min = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMinIndex(x, b);
        min.push(b[j] - x);
    }

    const boulders = createArrayOfBoulders(a, b);
    // console.log(boulders);
    const max = [];
    for (let i = 0; i < a.length; i++) {
        if (boulders.length > 0) {
            let bi = lowerBound(i, boulders);
            let j = boulders[bi];

            if (j === i) {
                if (bi === boulders.length - 1) {
                    j = b.length - 1;
                } else {
                    j = boulders[bi + 1];
                }
            }

            if (j > i) {
                j--;
            }

            max.push(b[j] - a[i]);
            // const j = pickMaxIndex(i, a, b);
            // max.push(b[j] - a[i]);
        } else {
            max.push(b[b.length - 1] - a[i]);
        }
    }

    console.log(min.join(' '));
    console.log(max.join(' '));
}

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].split(' ').map(Number);
        const b = data[i + 2].split(' ').map(Number);

        solve(a, b);
    }
});

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

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

// Finds index where x should be
function lowerBound(x, a) {
    let iMin = 0;
    let iMax = a.length - 1;
    // 1 2 3 4 (1) => 0
    // 1 2 3 4 (2) => 1
    // 1 2 3 4 (3) => 2
    // 1 2 3 4 (4) => 3
    // 1 2 3 4 (5) => 3
    while (iMax - iMin > 0) {
        const iMiddle = Math.floor((iMax + iMin) / 2);

        if (a[iMiddle] >= x) {
            iMax = iMiddle;
        } else {
            // a[iMiddle] < x
            iMin = iMiddle + 1;
        }
    }

    if (x > a[iMin]) {
        return Math.min(iMin + 1, a.length - 1);
    }

    return iMin;
}

// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));

function pickMinIndex(x, b) {
    for (let j = 0; j < b.length; j++) {
        return lowerBound(x, b);
    }
}

function pickMaxIndex(i, a, b) {
    for (let j = i; j < b.length - 1; j++) {
        if (a[j + 1] > b[j]) {
            return j;
        }
    }

    return b.length - 1;
}

// indecies of elements which cannot be moved by -1
function createArrayOfBoulders(a, b) {
    const boulders = [];

    for (let i = 1; i < a.length; i++) {
        if (a[i] > b[i - 1]) {
            boulders.push(i);
        }
    }

    return boulders;
}

function solve(a, b) {
    const min = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMinIndex(x, b);
        min.push(b[j] - x);
    }

    const boulders = createArrayOfBoulders(a, b);
    // console.log(boulders);
    const max = [];
    for (let i = 0; i < a.length; i++) {
        if (boulders.length > 0) {
            let bi = lowerBound(i, boulders);
            let j = boulders[bi];
            if (j > i) {
                j--;
            } else if (j === i) {
                // last boulder
                if (bi === boulders.length - 1) {
                    j = b.length - 1;
                } else {
                    j = boulders[bi + 1] - 1;
                }
            }
            max.push(b[j] - a[i]);
        } else {
            max.push(b[b.length - 1] - a[i]);
        }
    }

    console.log(min.join(' '));
    console.log(max.join(' '));
}

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].split(' ').map(Number);
        const b = data[i + 2].split(' ').map(Number);

        solve(a, b);
    }
});

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

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

// Finds index where x should be
function lowerBound(x, a) {
    let iMin = 0;
    let iMax = a.length - 1;
    // 1 2 3 4 (1) => 0
    // 1 2 3 4 (2) => 1
    // 1 2 3 4 (3) => 2
    // 1 2 3 4 (4) => 3
    // 1 2 3 4 (5) => 3
    while (iMax - iMin > 0) {
        const iMiddle = Math.floor((iMax + iMin) / 2);

        if (a[iMiddle] >= x) {
            iMax = iMiddle;
        } else {
            // a[iMiddle] < x
            iMin = iMiddle + 1;
        }
    }

    if (x > a[iMin]) {
        return Math.min(iMin + 1, a.length - 1);
    }

    return iMin;
}

// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));

function pickMinIndex(x, b) {
    for (let j = 0; j < b.length; j++) {
        return lowerBound(x, b);
    }
}

function pickMaxIndex(i, a, b) {
    for (let j = i; j < b.length - 1; j++) {
        if (a[j + 1] > b[j]) {
            return j;
        }
    }

    return b.length - 1;
}

// indecies of elements which cannot be moved by -1
function createArrayOfBoulders(a, b) {
    const boulders = [];

    for (let i = 1; i < a.length; i++) {
        if (a[i] > b[i - 1]) {
            boulders.push(i);
        }
    }

    return boulders;
}

function solve(a, b) {
    const min = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMinIndex(x, b);
        min.push(b[j] - x);
    }

    const boulders = createArrayOfBoulders(a, b);
    // console.log(boulders);
    const max = [];
    for (let i = 0; i < a.length; i++) {
        if (boulders.length > 0) {
            let bi = boulders[lowerBound(i, boulders)];
            if (bi > i) {
                bi--;
            } else if (bi === i) {
                bi = b.length - 1;
            }
            max.push(b[bi] - a[i]);
        } else {
            max.push(b[b.length - 1] - a[i]);
        }
    }

    console.log(min.join(' '));
    console.log(max.join(' '));
}

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].split(' ').map(Number);
        const b = data[i + 2].split(' ').map(Number);

        solve(a, b);
    }
});

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

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

// Finds index where x should be
function lowerBound(x, a) {
    let iMin = 0;
    let iMax = a.length - 1;
    // 1 2 3 4 (1) => 0
    // 1 2 3 4 (2) => 1
    // 1 2 3 4 (3) => 2
    // 1 2 3 4 (4) => 3
    // 1 2 3 4 (5) => 3
    while (iMax - iMin > 0) {
        const iMiddle = Math.floor((iMax + iMin) / 2);

        if (a[iMiddle] >= x) {
            iMax = iMiddle;
        } else {
            // a[iMiddle] < x
            iMin = iMiddle + 1;
        }
    }

    if (x > a[iMin]) {
        return Math.min(iMin + 1, a.length - 1);
    }

    return iMin;
}

// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));

function pickMinIndex(x, b) {
    for (let j = 0; j < b.length; j++) {
        return lowerBound(x, b);
    }
}

function pickMaxIndex(i, a, b) {
    for (let j = i; j < b.length - 1; j++) {
        if (a[j + 1] > b[j]) {
            return j;
        }
    }

    return b.length - 1;
}

// indecies of elements which cannot be moved by -1
function createArrayOfBoulders(a, b) {
    const boulders = [];

    for (let i = 1; i < a.length; i++) {
        if (a[i] > b[i - 1]) {
            boulders.push(i);
        }
    }

    return boulders;
}

function solve(a, b) {
    const min = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMinIndex(x, b);
        min.push(b[j] - x);
    }

    const boulders = createArrayOfBoulders(a, b);
    // console.log(boulders);
    const max = [];
    for (let i = 0; i < a.length; i++) {
        if (boulders.length > 0) {
            let bi = boulders[lowerBound(i, boulders)];
            if (bi > i) {
                bi--;
            }
            max.push(b[bi] - a[i]);
        } else {
            max.push(b[b.length - 1] - a[i]);
        }
    }

    console.log(min.join(' '));
    console.log(max.join(' '));
}

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].split(' ').map(Number);
        const b = data[i + 2].split(' ').map(Number);

        solve(a, b);
    }
});

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

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

// Finds index where x should be
function lowerBound(x, a, iMin = 0, iMax = a.length - 1) {
    // let iMin = 0;
    // let iMax = a.length - 1;
    // 1 2 3 4 (1) => 0
    // 1 2 3 4 (2) => 1
    // 1 2 3 4 (3) => 2
    // 1 2 3 4 (4) => 3
    // 1 2 3 4 (5) => 3
    while (iMax - iMin > 0) {
        const iMiddle = Math.floor((iMax + iMin) / 2);

        if (a[iMiddle] >= x) {
            iMax = iMiddle;
        } else {
            // a[iMiddle] < x
            iMin = iMiddle + 1;
        }
    }

    if (x > a[iMin]) {
        return Math.min(iMin + 1, a.length - 1);
    }

    return iMin;
}

// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));

function pickMinIndex(x, b) {
    for (let j = 0; j < b.length; j++) {
        return lowerBound(x, b, 0, j);
    }
}

function pickMaxIndex(i, a, b) {
    for (let j = i; j < b.length - 1; j++) {
        if (a[j + 1] > b[j]) {
            return j;
        }
    }

    return b.length - 1;
}

// indecies of elements which cannot be moved by -1
function createArrayOfBoulders(a, b) {
    const boulders = [];

    for (let i = 1; i < a.length; i++) {
        if (a[i] > b[i - 1]) {
            boulders.push(i);
        }
    }

    return boulders;
}

function solve(a, b) {
    const min = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMinIndex(x, b);
        min.push(b[j] - x);
    }

    const boulders = createArrayOfBoulders(a, b);
    // console.log(boulders);
    const max = [];
    for (let i = 0; i < a.length; i++) {
        if (boulders.length > 0) {
            let bi = boulders[lowerBound(i, boulders)];
            if (bi > i) {
                bi--;
            }
            max.push(b[bi] - a[i]);
        } else {
            max.push(b[b.length - 1] - a[i]);
        }
    }

    console.log(min.join(' '));
    console.log(max.join(' '));
}

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].split(' ').map(Number);
        const b = data[i + 2].split(' ').map(Number);

        solve(a, b);
    }
});

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

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

// Finds index where x should be
function lowerBound(x, a) {
    let iMin = 0;
    let iMax = a.length - 1;
    // 1 2 3 4 (1) => 0
    // 1 2 3 4 (2) => 1
    // 1 2 3 4 (3) => 2
    // 1 2 3 4 (4) => 3
    // 1 2 3 4 (5) => 3
    while (iMax - iMin > 0) {
        const iMiddle = Math.floor((iMax + iMin) / 2);

        if (a[iMiddle] >= x) {
            iMax = iMiddle;
        } else {
            // a[iMiddle] < x
            iMin = iMiddle + 1;
        }
    }

    if (x > a[iMin]) {
        return Math.min(iMin + 1, a.length - 1);
    }

    return iMin;
}

// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));
// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));

function pickMinIndex(x, b) {
    for (let j = 0; j < b.length; j++) {
        return lowerBound(x, b, 0, j);
    }
}

function pickMaxIndex(i, a, b) {
    for (let j = i; j < b.length - 1; j++) {
        if (a[j + 1] > b[j]) {
            return j;
        }
    }

    return b.length - 1;
}

// indecies of elements which cannot be moved by -1
function createArrayOfBoulders(a, b) {
    const boulders = [];

    for (let i = 1; i < a.length; i++) {
        if (a[i] > b[i - 1]) {
            boulders.push(i);
        }
    }

    return boulders;
}

function solve(a, b) {
    const min = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMinIndex(x, b);
        min.push(b[j] - x);
    }

    const boulders = createArrayOfBoulders(a, b);
    // console.log(boulders);
    const max = [];
    for (let i = 0; i < a.length; i++) {
        if (boulders.length > 0) {
            let bi = boulders[lowerBound(i, boulders)];
            if (bi !== i) {
                bi--;
            }
            max.push(b[bi] - a[i]);
        } else {
            max.push(b[b.length - 1] - a[i]);
        }
    }

    console.log(min.join(' '));
    console.log(max.join(' '));
}

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].split(' ').map(Number);
        const b = data[i + 2].split(' ').map(Number);

        solve(a, b);
    }
});

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

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

function pickMinIndex(x, b /* a is sorted */, minMap) {
    for (let j = 0; j < b.length; j++) {
        const num = b[j];
        if (
            num >= x
        ) {
            if (b[j + 1] === num && minMap[j + 1] === undefined) {
                continue;
            }

            return j;
        }
    }

    throw new Error('Cant find min');
}

function pickMaxIndex(x, xi, b /* a is sorted */, minMap, xMap) {
    for (let j = xMap[xi] + 1; j < b.length; j++) {
        if (minMap[j] !== undefined) {
            return j - 1;
        }
    }

    return b.length - 1;
}

function solve(a, b) {
    const minMap = {};
    const xMap = {};
    const min = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMinIndex(x, b, minMap);
        min.push(b[j] - x);
        minMap[j] = true;
        xMap[i] = j;
    }

    const max = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMaxIndex(x, i, b, minMap, xMap);
        max.push(b[j] - x);
    }

    console.log(min.join(' '));
    console.log(max.join(' '));
}

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].split(' ').map(Number);
        const b = data[i + 2].split(' ').map(Number);

        solve(a, b);
    }
});

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

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

function pickMinIndex(x, a /* a is sorted */) {
    for (let i = 0; i < a.length; i++) {
        const num = a[i];
        if (num >= x && a[i + 1] !== num) {
            return i;
        }
    }

    throw new Error('Cant find min');
}

function pickMaxIndex(x, xi, b /* a is sorted */, minMap, xMap) {
    for (let j = xMap[xi] + 1; j < b.length; j++) {
        if (minMap[j] !== undefined) {
            return j - 1;
        }
    }

    return b.length - 1;
}

function solve(a, b) {
    const minMap = {};
    const xMap = {};
    const min = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMinIndex(x, b);
        min.push(b[j] - x);
        minMap[j] = true;
        xMap[i] = j;
    }

    const max = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMaxIndex(x, i, b, minMap, xMap);
        max.push(b[j] - x);
    }

    console.log(min.join(' '));
    console.log(max.join(' '));
}

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].split(' ').map(Number);
        const b = data[i + 2].split(' ').map(Number);

        solve(a, b);
    }
});

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

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

function pickMinIndex(x, a /* a is sorted */) {
    for (let i = 0; i < a.length; i++) {
        const num = a[i];
        if (num >= x) {
            return i;
        }
    }

    throw new Error('Cant find min');
}

function pickMaxIndex(x, xi, b /* a is sorted */, minMap, xMap) {
    for (let j = xMap[xi] + 1; j < b.length; j++) {
        if (minMap[j] !== undefined) {
            return j - 1;
        }
    }

    return b.length - 1;
}

function solve(a, b) {
    const minMap = {};
    const xMap = {};
    const min = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMinIndex(x, b);
        min.push(b[j] - x);
        minMap[j] = true;
        xMap[i] = j;
    }

    const max = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMaxIndex(x, i, b, minMap, xMap);
        max.push(b[j] - x);
    }

    console.log(min.join(' '));
    console.log(max.join(' '));
}

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].split(' ').map(Number);
        const b = data[i + 2].split(' ').map(Number);

        solve(a, b);
    }
});

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

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

function pickMinIndex(x, a /* a is sorted */) {
    for (let i = 0; i < a.length; i++) {
        const num = a[i];
        if (num >= x) {
            return i;
        }
    }

    throw new Error('Cant find min');
}

function pickMaxIndex(x, xi, a /* a is sorted */, minMap) {
    for (let i = a.length - 1; i >= 0; i--) {
        const num = a[i];
        if (num < x) {
            throw new Error(`Cant find max ${x}`);
        }

        if (
            minMap[i] === undefined ||
            minMap[i] === xi
        ) {
            return i;
        }
    }

    throw new Error(`Cant find max ${x}`);
}

function solve(a, b) {
    const minMap = {};
    const min = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMinIndex(x, b);
        min.push(b[j] - x);
        minMap[j] = i;
    }

    const max = [];
    for (let i = 0; i < a.length; i++) {
        const x = a[i];
        const j = pickMaxIndex(x, i, b, minMap);
        max.push(b[j] - x);
    }

    console.log(min.join(' '));
    console.log(max.join(' '));
}

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].split(' ').map(Number);
        const b = data[i + 2].split(' ').map(Number);

        solve(a, b);
    }
});