//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 N = nextInt();
  var list = nextIntArray();
  var L = 0;
  var R = 0;
  var turn = true;
  while(list.length > 0){
  	if(turn){
  		if(list[0] > list[list.length - 1]){
  			L += list.shift();
  		}else{
  			L += list.pop();
  		}
  		turn = false;
  	}else{
  		if(list[0] > list[list.length - 1]){
  			R += list.shift();
  		}else{
  			R += list.pop();
  		}
  		turn = true;
  	}
  }
  myout(L + " " + R);
}

;(function () {

	readline();
	var n = readline().split(' ').map(Number);
	var a = 0, b = 0, f = true;

	while (n.length) {
		if (n[0] > n[n.length - 1]) {
			if (f) a += n.shift();
			else b += n.shift();
		} else {
			if (f) a += n.pop();
			else b += n.pop();
		}

		f = !f;
	}

	print(a + " " + b);

}).call(this);

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 numCards = integers[0];

	var cards = tokenizeIntegers(readline());
	var left = 0, right = cards.length-1;
	var totals = [0, 0];
	for (var i = 0; i < cards.length; i += 1) {
		if (cards[left] > cards[right]) {
			totals[i%2] += cards[left];
			left += 1;
		}
		else {
			totals[i%2] += cards[right];
			right -= 1;
		}
	}

	print(totals.join(' '));
}

main();

var n = parseInt(readline()) - 1,
	a = readline().split(" ").map(Number),
	i = 0, v = 1, s = 0, d = 0, k;
while (i <= n) {
	if (a[i] > a[n])  {
		k = a[i];
		i++;
	} else {
		k = a[n];
		n--;
	}
	if (v) {
		s += k;
		v = 0;
    } else {
		d += k;
		v = 1;
    }
}
write(s + " " + d);

var n = parseInt(readline());
var cards = readline().split(' ');

for (var i = 0; i < n; i++) {
  cards[i] = parseInt(cards[i]);
}

var sereja = 0;
var dima = 0;
var turn = 0;

while (cards.length > 0) {
  if (turn % 2 == 0) {
    if (cards[0] > cards[cards.length - 1]) {
      sereja += cards[0];
      cards.splice(0, 1);
    } else {
      sereja += cards[cards.length - 1];
      cards.splice(cards.length - 1, 1);
    }
  } else {
    if (cards[0] > cards[cards.length - 1]) {
      dima += cards[0];
      cards.splice(0, 1);
    } else {
      dima += cards[cards.length - 1];
      cards.splice(cards.length - 1, 1);
    }
  }

  turn++;
}

print(sereja, dima);

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 numCards = integers[0];

  var cards = tokenizeIntegers(readline());
  var left = 0, right = cards.length-1;
  var isSergiiTurn = true;
  var sergii = 0;
  var dima = 0;
  for (var i = 0; i < cards.length; i += 1) {
    if (cards[left] > cards[right]) {
      value = cards[left];
      left += 1;
    }
    else {
      value = cards[right];
      right -= 1;
    }

    if (isSergiiTurn) {
      sergii += value;
      isSergiiTurn = false;
    } else {
      dima += value;
      isSergiiTurn = true;
    }
  }

  print(sergii + ' ' + dima);
}

main();

// Input 結尾的每一行應有換行符號，不然readline()會讀不到
var linedataCount = readline();
var linedata = readline().split(" ");
var round = linedata.length;
var sScore=0;
var dScore=0;
var bigvalue;

//var num=0;
while(linedata.length>0)
{
//num++;

     //print('round :'+ i);
     bigvalue = compare();
     sScore +=parseInt(bigvalue);
     //print('s:'+ sScore);
     bigvalue = compare();
     dScore +=parseInt(bigvalue);
     //print('d :'+ dScore);
//if(num>=4)
//break;
}

function compare()
{

     var firstvalue = linedata[0];
     var finalvalue = linedata[linedata.length-1];
     var value;
     if(!(firstvalue&&finalvalue))
     {
           return 0;
     }
     if(parseInt(firstvalue)>parseInt(finalvalue))
     {
        value = firstvalue;
        linedata.shift();
        //print('firstvalue>finalvalue');

     }
     else if (parseInt(firstvalue)==parseInt(finalvalue))
     {
          value = firstvalue;
          linedata.shift();
          //print('firstvalue=finalvalue');
     }
     else
     {
          value = finalvalue;
          linedata.pop();
          //print('firstvalue<finalvalue');
     }
    //print('bigvalue:'+value);
    //print('new linedata : ' + linedata);
    return value;
}
print(sScore,dScore);

var n=parseInt(readline());
var myArray=readline().split(' ').map(Number);
// print(myArray)
var arr=[];
var s=0;
var d=0;
left=0;
right=n-1;

while(left<=right){

  if(myArray[left]>myArray[right]){

    // print(myArray[left])
      arr.push(myArray[left]);
      left++;
  }else{
     arr.push(myArray[right]);
     right--;
  }
}
// print(arr);

for(var i=0; i<arr.length; i++){
  if(i%2==0){
    s=s+arr[i];
  }else{
    d=d+arr[i]
  }
}
print(s +" "+d);

var num = parseInt(readline());
var row = readline().split(" ").map(x => parseInt(x));

var shreeja = 0;
var dima = 0;
var flag = true; // 1 Shreeja, 0 dima;

function addToValue(value) {
    if (flag) {
        shreeja += value;
    } else {
        dima += value;
    }
}

for (var i = 0; i < num; i++) {
    if (row[0] > row[row.length - 1]) {
        // first Value is bigger
        var val = row.shift();
        addToValue(val);
    } else {
        // last Value is bigger
        var value = row.pop();
        addToValue(value);
    }

    flag = !flag;
}

print(shreeja + " " + dima);

readline();
var nums=readline().split(' ').map(Number);
var Sereja=0;
var Dima=0;
var i = 0;
var j = nums.length - 1;
var turn=0;
 while (i <= j) {
     if (nums[i] > nums[j] ) {
        if(turn%2==0)
        Sereja+=nums[i];

         else
         Dima+=nums[i];
        i++;}
else{
if(turn%2==0)

Sereja+=nums[j];
else
Dima+=nums[j];
j--;}
turn++;
 }

print(Sereja+" "+Dima)

var n = readline();
var length = parseInt(n, 10);
var arr = readline();
arr = arr.split(' ')

for (var index = 0; index < length; index++) {
    arr[index] = parseInt(arr[index], 10);
}

var left = 0;
var right = length-1;
var per1 = 0;
var per2 = 0;
var mid = ( left + right)/2;
for (var index = left; index <= mid; index++) {

    if (left == right ){
        per1 +=arr[left];
        break;
    }

    if(arr[left] > arr[right] ){
        per1 += arr[left];
        left++;
    } else {
        per1 += arr[right];
        right--;
    }

    if(arr[left] > arr[right] ){
        per2 += arr[left];
        left++;
    } else {
        per2 += arr[right];
        right--;
    }
}
print(`${per1 + " " + per2}`)

var n = parseInt(readline().split(' '));
    var input = readline().split(' ');
    input.forEach(function(elem){elem = parseInt(elem);});
    var sereja = 0, dima = 0, move=1;
    while(input.length>0)
    {
        var points = Math.max(input[0],input[input.length-1]);
        if(points==input[0]) input.splice(0,1);
        else input.splice(input.length-1,1);
        if(move%2) sereja+=points;
        else dima+=points;
        move++;
    }
    print(sereja+' '+dima);

var
    num      = parseInt(readline()),
    arr      = readline().split(" "),
    ser      = 0,
    dim      = 0,
    isSer    = true
;

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

while(arr.length > 0) {
    var add = 0;
    if (arr[0] > arr[arr.length-1]) {
        add = arr[0];
        arr.shift();
    } else {
        add = arr[arr.length-1];
        arr.pop();
    }

    if (isSer) {
        ser += add;
    } else {
        dim += add;
    }

    isSer = !isSer;
}

print(ser + " " + dim);

function main() {
    var n = Number(readline());
    var data = readline().split(' ').map(Number);
    var i=0;
    var j = n-1;
    var sum1 = 0;
    var sum2 = 0;
    var turn = true;
    while(i<=j){
        if(turn){
            sum1+=Math.max(data[i], data[j])
        } else {
            sum2 += Math.max(data[i], data[j])
        }
        turn = !turn;
        if(data[i] > data[j]){
            i++;
        } else {
            j--;
        }
    }
    print(sum1 + " " + sum2)
}

main()

//  381A    Сережа и Дима

var n = parseInt(readline());

//var input_line = readline().split(' ').map(Number);
var arr = readline().split(' ').map(Number);

var countS = 0;
var countD = 0;
var i = 0;

n --;

while (i <= n) {
    if (arr[i] > arr[n]) {
        countS += arr[i];
        i ++;
    } else {
        countS += arr[n];
        n --;
    };

    if (i <= n) {
        if (arr[i] > arr[n]) {
            countD += arr[i];
            i ++;
        } else {
            countD += arr[n];
            n --;
        };
    };
}

print(countS + ' ' + countD + '\n');

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

// for (var i = 0; i < n; i++) {
//   cards[i] = parseInt(cards[i]);
// }

var sereja = 0;
var dima = 0;
var turn = 0;

while (cards.length > 0) {
  if (turn % 2 == 0) {
    if (cards[0] > cards[cards.length - 1]) {
      sereja += cards[0];
      cards.splice(0, 1);
    } else {
      sereja += cards[cards.length - 1];
      cards.splice(cards.length - 1, 1);
    }
  } else {
    if (cards[0] > cards[cards.length - 1]) {
      dima += cards[0];
      cards.splice(0, 1);
    } else {
      dima += cards[cards.length - 1];
      cards.splice(cards.length - 1, 1);
    }
  }

  turn++;
}

print(sereja, dima);

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

var sum_sereja = 0,
	sum_dima = 0;
var score;

var left =0, right = n - 1;

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

	if(cards[left]> cards[right]){
		score = cards[left];
		left ++;
	}else{
		score = cards[right];
		right --;
	}

	if(i%2==0) sum_sereja += score;
	else sum_dima +=score;
}

print(sum_sereja, sum_dima);

readline();
var a = readline().split(" "),o=[0,0],sh=0;
while(a.length) o[+(sh++%2)]+=+a[+a[0]>+a[a.length-1]?"shift":"pop"]();
print(o.join(" "));

(function() {
    var i , n = parseInt(readline());
    var cards = readline().split(' ');
    var ser = 0, dima = 0, l = 0 , r = n - 1;
    for( i = 0 ; i < n ; ++i ){
        if (i % 2 == 0)
           ser += parseInt(cards[l]) > parseInt(cards[r]) ?
                    parseInt(cards[l++]) : parseInt(cards[r--]);
        else
            dima += parseInt(cards[l]) > parseInt(cards[r]) ?
                    parseInt(cards[l++]) : parseInt(cards[r--]);
    }
    print(ser+" "+dima);
})();

"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();
  const x2 = readline()
    .split(" ")
    .map((x) => +x);
  serejaAndDima(x2);
}

function serejaAndDima(cards) {
  let serejaPoints = 0;
  let dimaPoints = 0;
  let coin = true;
  let point;

  while (cards.length) {
    if (cards[cards.length - 1] > cards[0]) {
      point = cards.pop();
    } else {
      point = cards.shift();
    }

    if (coin) {
      serejaPoints += point;
    } else {
      dimaPoints += point;
    }

    coin = !coin;
  }

  console.log(serejaPoints, dimaPoints);
}

const readline = require('readline');

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

let counter = 0;
let cards = [];

rl.on('line', (input) => {
    if (counter++ === 0) return;
    let line = input.split(' ');
    line.forEach(el => {
        cards.push(parseInt(el));
    });
    rl.close();
    let sol = solve(cards);
    console.log(sol[0], sol[1]);
});

const solve = (cards) => {
    let l = 0,
        r = cards.length - 1;
    let isSerejaturn = true;
    let serejaScore = 0;
    let dimaScore = 0;

    while (l <= r) {
        if (isSerejaturn) {
            if (cards[l] > cards[r]) {
                serejaScore += cards[l++];

            } else {
                serejaScore += cards[r--];
            }
            isSerejaturn = false;
        } else {
            if (cards[l] > cards[r]) {
                dimaScore += cards[l++];

            } else {
                dimaScore += cards[r--];
            }
            isSerejaturn = true;
        }
    }

    return [serejaScore, dimaScore];

}

'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 numOfCards = readline()
  const cards = readline().split(' ').map(card => parseInt(card))

  helper(numOfCards, cards)
}

function helper(numOfCards, cards) {
  let left = 0
  let right = numOfCards - 1
  let firstPlayerSum = 0
  let secondPlayerSum = 0
  let isFirstPlayerTurn = true

  while (left <= right) {
    if (cards[left] > cards[right]) {
      if (isFirstPlayerTurn) {
        firstPlayerSum += cards[left]
      } else {
        secondPlayerSum += cards[left]
      }
      left++
    } else {
      if (isFirstPlayerTurn) {
        firstPlayerSum += cards[right]
      } else {
        secondPlayerSum += cards[right]
      }
      right--
    }

    isFirstPlayerTurn = !isFirstPlayerTurn
  }

  console.log(firstPlayerSum + ' ' + secondPlayerSum)
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function print(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // input
  const n = readline();
  const nums = readline().split(' ').map(x => parseInt(x));
  let l = 0;
  let r = nums.length - 1;
  let first = 0, second = 0;
  let turn = 1;
  while(l <= r) {
    if (nums[l] > nums[r]) {
      if (turn > 0) {
        first += nums[l];
      } else {
        second += nums[l];
      }
      l++;
    } else {
      if (turn > 0) {
        first += nums[r];
      } else {
        second += nums[r];
      }
      r--;
    }
    turn *= -1;
  }
  // output
  print(`${first} ${second}`);
}

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);
  let i = 0;
  let l = 0;
  let r = arr.length - 1;

  let player1 = 0;
  let player2 = 0;
  let isTurn = 0;

  while(i < arr.length) {
    if (arr[l] > arr[r]) {
      if (isTurn === 0) {
        player1 += arr[l];
      }
      else {
        player2 += arr[l];
      }
      l++;
    }
    else {
      if (isTurn === 0) {
        player1 += arr[r];
      }
      else {
        player2 += arr[r];
      }
      r--;
    }

    isTurn = isTurn ? 0 : 1;

    i++;
  }

  console.log(player1, player2);

  c++;
});

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

let input_stdin = "";
let input = "";
let input_currentline = 0;

function readLine() {
    return input[input_currentline++];
}

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

process.stdin.on('end', function () {
    input = input_stdin.split("\n");
    main();
});

// your code goes here
function main() {
    const T=parseInt(readLine());
    let A = 0;
    let B = 0;
    let cards = readLine().split(' ').map(x => +x);
    for(let k = 0; k < T; k++) {
       if ( cards[0] >= cards[cards.length - 1]) {
            k%2===0 ? A += Number(cards.shift()) : B += Number(cards.shift())
       }
       else {
            k%2===0 ? A += Number(cards.pop()) : B += Number(cards.pop())
       }
    }
    console.log(A + ' ' + B);
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let n = readline().toLowerCase();
    let cards = readline().split(' ').map(x => parseInt(x));
    let DimaTurn = false;
    let dimaSum = 0;
    let serejaSum = 0;

    while (cards.length != 0){
       let num = cards[cards.length -1] >= cards[0] ? cards.pop() : cards.shift();
       if (DimaTurn) dimaSum +=num
        else serejaSum+= num;

        DimaTurn = !DimaTurn
    }

    console.log(serejaSum, dimaSum)

}

const readline = require('readline');

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

let numberOfCards;
let arrOfCards;
let pointsOfSereja = 0;
let pointsOfDima = 0;
let turnsCounter = 0 ;
let temp = 0 ;
rl.on("line", (input) => {
    if (!numberOfCards) {
        numberOfCards = parseInt(input.split(" "));
       // console.log(numberOfCards, typeof (numberOfCards))
    } else {
        if (!arrOfCards) arrOfCards = input.split(" ").map(Number)
        while (arrOfCards != 0) {
            turnsCounter++
            let lastIndex = arrOfCards[arrOfCards.length-1];
           // console.log(lastIndex)
            if (arrOfCards[0] > lastIndex) {
               temp =  arrOfCards.shift()
               // console.log(arrOfCards)
            }
            else {
               temp = arrOfCards.pop()
            }
            if (turnsCounter % 2 === 0 ){
                pointsOfDima += temp
            }
            else{
                pointsOfSereja += temp
            }
          //  console.log(pointsOfSereja , pointsOfDima ,"\n" , arrOfCards.length)

        }
        console.log(pointsOfSereja , pointsOfDima)
        if (turnsCounter == numberOfCards) rl.close();

    }
})

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

var i = 0, j=n-1;

var k = [0, 0];
var x = 1;
while(i<=j){
	x++;
	k[x%2];

	if(s[i]>s[j]){
		k[x%2] += s[i];
		i++;
	}else{
		k[x%2] += s[j];
		j--;
	}
}

print(k[0], k[1]);

var x=parseInt(readline());

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

var left=0, right=arr.length-1;
var sereja=0, dima=0, turn=0;

while(left<=right){
  if(arr[left]>=arr[right]){
    if(turn===0){
      sereja+=arr[left];
      turn=1;
    }else{
      dima+=arr[left];
      turn=0;
    }
    left++;
  }else{
    if(turn===0){
      sereja+=arr[right];
      turn=1;
    }else{
      dima+=arr[right];
      turn=0;
    }
    right--;
  }
}

print(sereja+' '+dima);

var sergja = true;
var dima = false;
var n = parseInt(readline());
var input=readline().split(' ').map(x=>parseInt(x));
var i = 0;
var j = n-1;
var big;
var s=0;
var d=0;
while(n>0){
    if(input[i]>input[j]){
        big = input[i];
        i++;
    }
    else{
        big=input[j];
        j--;
    }

    if(sergja){
        s+=big;
        sergja=false;
        dima=true;
    }
    else{
        d+=big;
        sergja=true;
        dima=false;
    }
    n--;
}

print(s+" "+d);

var turn = 0;
var n = parseInt(readline());
var input=readline().split(' ').map(x=>parseInt(x));
var i = 0;
var j = n-1;
var big;
var s=0;
var d=0;
while(n>0){
    if(input[i]>input[j]){
        big = input[i];
        i++;
    }
    else{
        big=input[j];
        j--;
    }

    if(turn%2===0){
        s+=big;
    }
    else{
        d+=big;
    }
    turn++;
    n--;
}

print(s+" "+d);

var n = readline();
var nums = readline().split(' ').map(function(x){return parseInt(x)});
var r = [0, 0];
var m = {true:1,false:0};
var f = false;

while(nums.length) {
  r[m[f]] += (nums[0] > nums[nums.length-1]) ? nums.shift() : nums.pop();
  f = !f;
}
print(r[0] + ' ' + r[1]);

var len = readline()
  var cards = readline().split(' ').map(Number)

  var indexLeft = 0
  var indexRight = len - 1
  var playerAScore = 0
  var playerBScore = 0
  var playerATurn = true

  for (var i = 0; i < len; i++) {
    var biggestNumber
    if (cards[indexLeft] > cards[indexRight]) {
      biggestNumber = cards[indexLeft]
      indexLeft += 1
    } else {
      biggestNumber = cards[indexRight]
      indexRight -= 1
    }

    if (playerATurn) {
      playerAScore += biggestNumber
      playerATurn = false
    } else {
      playerBScore += biggestNumber
      playerATurn = true
    }
  }

  print(playerAScore + ' ' + playerBScore)

var inputLength = readline();
var input =  readline().split(" ").map(x => parseInt(x));
var players = [0, 0];
var turn = 0;
for (var i = 0; i < inputLength; i++) {
	if(input[i] > input[inputLength - 1]) {
		players[turn]+= input[i];
	} else {
		players[turn]+= input[inputLength - 1];
		inputLength--;
		i--;
	}
	turn = turn === 0 ? 1 : 0;
}
print(players[0] + ' ' + players[1]);

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 numCards = integers[0];

  var cards = tokenizeIntegers(readline());
  var left = 0, right = cards.length-1;
  var sergii = 0;
  var dima = 0;
  for (var i = 0; i < cards.length; i += 1) {
    if (cards[left] > cards[right]) {
      sergii += cards[left];
      left += 1;
    }
    else {
      dima += cards[right];
      right -= 1;
    }
  }

  print(sergii + ' ' + dima);
}

main();

// Input 結尾的每一行應有換行符號，不然readline()會讀不到
var linedataCount = readline();
var linedata = readline().split(" ");
var round = linedataCount/2;

var sScore=0;
var dScore=0;
var bigvalue;

for (var i=1;round>=i;i++)
{

     //print('round :'+ i);
     bigvalue = compare();
     sScore +=parseInt(bigvalue);
     //print('s:'+ sScore);
     bigvalue = compare();
     dScore +=parseInt(bigvalue);
     //print('d :'+ dScore);

}

function compare()
{
     var firstvalue = linedata[0];
     var finalvalue = linedata[linedata.length-1];
     var value;
     if(parseInt(firstvalue)>parseInt(finalvalue))
     {
        value = firstvalue;
        linedata.shift();
        //print('firstvalue>finalvalue');

     }
     else if (parseInt(firstvalue)==parseInt(finalvalue))
     {
          value = firstvalue;
          //print('firstvalue=finalvalue');

     }
     else
     {
          value = finalvalue;
          linedata.pop();
          //print('firstvalue<finalvalue');
     }
    //print('bigvalue:'+value);
    //print('new linedata : ' + linedata);
    return value;
}
print(sScore,dScore);

var n=parseInt(readline());
var myArray=readline().split(' ');
var s=0,d=0;
if(myArray.length == n){
 function sortArray(a,b){
    return b-a;
    }
    myArray.sort(sortArray);
    for(var i=0; i<myArray.length;i++){
      if(i%2==0){
        s=s+parseInt(myArray[i]);
      }else{
        d=d+parseInt(myArray[i]);
      }
    }
    print(s)
    print(d)

}

var n=parseInt(readline());
var myArray=readline().split(' ');
var s=0,d=0;
if(myArray.length == n){
 function sortArray(a,b){
    return b-a;
    }
    myArray.sort(sortArray);
    for(var i=0; i<myArray.length;i++){
      if(i%2==0){
        s=s+parseInt(myArray[i]);

      }else{
        d=d+parseInt(myArray[i]);
      }
    }
    print(s , d)

}

var n=parseInt(readline());
var myArray=readline().split(' ');
var s=0,d=0;
if(myArray.length == n){
 function sortArray(a,b){
    return b-a;
    }
    myArray.sort(sortArray);
    for(var i=0; i<myArray.length;i++){
      if(i%2==0){
        s=s+parseInt(myArray[i]);
      }else{
        d=d+parseInt(myArray[i]);
      }
    }
    print(s +" "+ d)
    // print(d)

}

var n=parseInt(readline());
var myArray=readline().split(' ').map(Number);
// print(myArray)
var arr=[];
var s=0;
var d=0;
left=0;
right=n-1;

while(left<=right){

  if(myArray[left]>myArray[right]){

    print(myArray[left])
      arr.push(myArray[left]);
      left++;
  }else{
     arr.push(myArray[right]);
     right--;
  }
}
// print(arr);

for(var i=0; i<arr.length; i++){
  if(i%2==0){
    s=s+arr[i];
  }else{
    d=d+arr[i]
  }
}
print(s +" "+d);

var n = readline();
var length = parseInt(n, 10);
var arr = readline();
arr = arr.split(' ')

for (var index = 0; index < length; index++) {
    arr[index] = parseInt(arr[index], 10);
}

var left = 0;
var right = length-1;
var per1 = 0;
var per2 = 0;

for (var index = left; index <= right; index++) {

    if(arr[left] > arr[right] ){
        per1 += arr[left];
        left++;
    } else {
        per1 += arr[right];
        right--;
    }

    if(arr[left] > arr[right] ){
        per2 += arr[left];
        left++;
    } else {
        per2 += arr[right];
        right--;
    }

    if (left == right ){
        per1 +=arr[left];
        break;
    }

}
print(`${per1 + " " + per2}`)

var n = readline();
var length = parseInt(n, 10);
var arr = readline();
arr = arr.split(' ')

for (var index = 0; index < length; index++) {
    arr[index] = parseInt(arr[index], 10);
}

var left = 0;
var right = length-1;
var per1 = 0;
var per2 = 0;
var mid = ( left + right)/2;
for (var index = left; index <= mid; index++) {

    if(arr[left] > arr[right] ){
        per1 += arr[left];
        left++;
    } else {
        per1 += arr[right];
        right--;
    }

    if(arr[left] > arr[right] ){
        per2 += arr[left];
        left++;
    } else {
        per2 += arr[right];
        right--;
    }

    if (left == right ){
        per1 +=arr[left];
        break;
    }

}
print(`${per1 + " " + per2}`)

(function() {
    var i , n = parseInt(readline());
    var cards = readline().split(' ');
    cards.sort(function(a,b){
        return parseInt(a) - parseInt(b);
    });
    var first = 0, second = 0;
    for( i = 0 ; i < n ; ++i ){
        if ( i % 2 === 1 ){
            first += parseInt(cards[i]);
        }else{
            second += parseInt(cards[i]);
        }
    }
    print(first+" "+second);
})();

(function() {
    var i , n = parseInt(readline());
    var cards = readline().split(' ');
    var ser = 0, dima = 0, l = 0 , r = n - 1;
    for( i = 0 ; i < n ; ++i ){
        if (i % 2 == 0)
           ser += cards[l] > cards[r] ? cards[l++] : cards[r--];
        else
            dima += cards[l] > cards[r] ? cards[l++] : cards[r--];
    }
    print(ser+" "+dima);
})();

(function() {
    var i , n = parseInt(readline());
    var cards = readline().split(' ');
    var ser = 0, dima = 0, l = 0 , r = n - 1;
    while ( l < r ){
       ser += parseInt(cards[l]) > parseInt(cards[r]) ?
               parseInt(cards[l++]) : parseInt(cards[r--]);
       if ( l > r ) break;
       dima += parseInt(cards[l]) > parseInt(cards[r]) ?
               parseInt(cards[l++]) : parseInt(cards[r--]);
    }
    print(ser+" "+dima);
})();

(function() {
    var i , n = parseInt(readline());
    var cards = readline().split(' ');
    cards.sort(function(a,b){
        return parseInt(a) - parseInt(b);
    });
    var ser = 0, dima = 0;
    for( i = 0 ; i < n ; ++i ){
        if ( i % 2 === 0 ){
            ser += parseInt(cards[i]);
        }else{
            dima += parseInt(cards[i]);
        }
    }
    print(ser+" "+dima);
})();

(function() {
    var i , n = parseInt(readline());
    var cards = readline().split(' ');
    var ser = 0, dima = 0, l = 0 , r = n - 1;
    while ( l < r ){
       ser += cards[l] > cards[r] ? parseInt(cards[l++]) : parseInt(cards[r--]);
       if ( l >= r ) break;
       dima += cards[l] > cards[r] ? parseInt(cards[l++]) : parseInt(cards[r--]);
    }
    print(ser+" "+dima);
})();

(function() {
    var i , n = parseInt(readline());
    var cards = readline().split(' ');
    var ser = 0, dima = 0, l = 0 , r = n - 1;
    while ( l < r ){
       ser += parseInt(cards[l]) > parseInt(cards[r]) ?
               parseInt(cards[l++]) : parseInt(cards[r--]);
       if ( l >= r ) break;
       dima += parseInt(cards[l]) > parseInt(cards[r]) ?
               parseInt(cards[l++]) : parseInt(cards[r--]);
    }
    print(ser+" "+dima);
})();

(function() {
    var i , n = parseInt(readline());
    var cards = readline().split(' ');
    var ser = 0, dima = 0, l = 0 , r = n - 1;
    for( i = 0 ; i < n ; ++i ){
        if (i % 2 == 0)
           ser += cards[l] > cards[r] ? parseInt(cards[l++]) : parseInt(cards[r--]);
        else
            dima += cards[l] > cards[r] ? parseInt(cards[l++]) : parseInt(cards[r--]);
    }
    print(ser+" "+dima);
})();

(function() {
    var i , n = parseInt(readline());
    var cards = readline().split(' ');
    cards.sort(function(a,b){
        return parseInt(a) - parseInt(b);
    });
    var first = 0, second = 0;
    for( i = 0 ; i < n ; ++i ){
        if ( i % 2 === 0 ){
            first += parseInt(cards[i]);
        }else{
            second += parseInt(cards[i]);
        }
    }
    print(first+" "+second);
})();

(function() {
    var i , n = parseInt(readline());
    var cards = readline().split(' ');
    cards.sort(function(a,b){
        return parseInt(b) - parseInt(a);
    });
    var ser = 0, dima = 0;
    for( i = 0 ; i < n ; ++i ){
        if ( i % 2 === 0 ){
            ser += parseInt(cards[i]);
        }else{
            dima += parseInt(cards[i]);
        }
    }
    print(ser+" "+dima);
})();

var num = parseInt(readline());
var row = readline().split(" ").map(x => parseInt(x));

var shreeja = 0;
var dima = 0;
var flag = true; // 1 Shreeja, 0 dima;

function addToValue(value) {
    if (flag) {
        shreeja += value;
    } else {
        dima += value;
    }
}

for (var i = 0; i < num; i++) {
    if (row[0] > row[row.length - 1]) {
        // first Value is bigger
        var val = row.unshift();
        addToValue(val);
    } else {
        // last Value is bigger
        var value = row.pop();
        addToValue(value);
    }

    flag = !flag;
}

print(shreeja + " " + dima);

const readline = require('readline');

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

let numberOfCards;
let arrOfCards;
let pointsOfSereja = 0;
let pointsOfDima = 0;
let turnsCounter = 0 ;
let temp = 0 ;
rl.on("line", (input) => {
    if (!numberOfCards) {
        numberOfCards = parseInt(input.split(" "));
       // console.log(numberOfCards, typeof (numberOfCards))
    } else {
        if (!arrOfCards) arrOfCards = input.split(" ").map(Number)
        while (arrOfCards != 0) {
            turnsCounter++
            let lastIndex = arrOfCards.length;
            if (arrOfCards[0] > lastIndex) {
               temp =  arrOfCards.shift()
               // console.log(arrOfCards)
            }
            else {
               temp = arrOfCards.pop()
            }
            if (turnsCounter % 2 === 0 ){
                pointsOfDima += temp
            }
            else{
                pointsOfSereja += temp
            }
          //  console.log(pointsOfSereja , pointsOfDima ,"\n" , arrOfCards.length)

        }
        console.log(pointsOfSereja , pointsOfDima)
        if (turnsCounter == numberOfCards) rl.close();

    }
})

const readline = require('readline');

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

let numberOfCards;
let arrOfCards;
let pointsOfSereja = 0;
let pointsOfDima = 0;
let turnsCounter = 1 ;
let temp = 0 ;
rl.on("line", (input) => {
    if (!numberOfCards) {
        numberOfCards = parseInt(input.split(" "));
       // console.log(numberOfCards, typeof (numberOfCards))
    } else {
        if (!arrOfCards) arrOfCards = input.split(" ").map(Number)
        while (arrOfCards != 0) {
            let lastIndex = arrOfCards.length;
            if (arrOfCards[0] > lastIndex) {
               temp =  arrOfCards.shift()
               // console.log(arrOfCards)
            }
            else {
               temp = arrOfCards.pop()
            }
            if (turnsCounter % 2 === 0 ){
                turnsCounter++

                pointsOfDima += temp
            }
            else{
                turnsCounter++

                pointsOfSereja += temp
            }
          //  console.log(pointsOfSereja , pointsOfDima ,"\n" , arrOfCards.length)

        }
        console.log(pointsOfSereja , pointsOfDima)
        if (turnsCounter == numberOfCards) rl.close();

    }
})


var nmxy = readline().split(' ').map(Number);
var n = nmxy[0];
var m = nmxy[1];
var x = nmxy[2];
var y = nmxy[3];
var a = readline().split(' ').map(Number);
var b = readline().split(' ').map(Number);
var ans = [];
var i = 0;
var j = 0;
while (i<n){
    while (j<m){
		if (a[i]-x <= b[j] && b[j] <= a[i]+y) {
			ans.push(i+1, j+1);
			j++;
			break;
		}
		else if (b[j] < a[i]-x) j++;
		else if (b[j] > a[i]+y) break;
	}
	i++;
}
print (ans.length/2);
for (var k=0; k<ans.length; k=k+2){
	print (ans[k], ans[k+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()
function main() {
  const input = readline().split(' ')
  const [people, vests, reduction, increase] = input
  const desiredSizes = readline().split(' ').map(size => parseInt(size))
  const availableSizes = readline().split(' ').map(size => parseInt(size))

  helper(desiredSizes, availableSizes, parseInt(reduction), parseInt(increase))
}

function helper(desiredSizes, availableSizes, reduction, increase) {
    let result = []
    let currentSizeIndex = 0
    let count = 0
    let pairs = ''

    for (let i = 0; i < desiredSizes.length; i++) {
        let min = desiredSizes[i] - reduction
        let max = desiredSizes[i] + increase

        while (currentSizeIndex < availableSizes.length) {
            if (availableSizes[currentSizeIndex] > max) {
                break;
            }

            if (availableSizes[currentSizeIndex] >= min) {
                count++;
                pairs += `\n${i + 1} ${currentSizeIndex + 1}`;
                currentSizeIndex++;
                break;
            }
            currentSizeIndex++;
        }

        if (currentSizeIndex === availableSizes.length) break;
    }

    console.log(`${count}${pairs}`);
}

'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 input = readline().split(' ').map(Number)
  const [people, vests, reduction, increase] = input
  const desiredSizes = readline().split(' ').map(Number)
  const availableSizes = readline().split(' ').map(Number)

  helper(desiredSizes, availableSizes, parseInt(reduction), parseInt(increase))
}

function helper(desiredSizes, availableSizes, reduction, increase) {
    let result = []
    let currentSizeIndex = 0
    let count = 0
    let pairs = ''

    for (let i = 0; i < desiredSizes.length; i++) {
        let min = desiredSizes[i] - reduction
        let max = desiredSizes[i] + increase

        while (currentSizeIndex < availableSizes.length) {
            if (availableSizes[currentSizeIndex] > max) {
                break;
            }

            if (availableSizes[currentSizeIndex] >= min) {
                count++;
                pairs += `\n${i + 1} ${currentSizeIndex + 1}`;
                currentSizeIndex++;
                break;
            }
            currentSizeIndex++;
        }

        if (currentSizeIndex === availableSizes.length) break;
    }

    console.log(`${count}${pairs}`);
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function printResult(x) {
    process.stdout.write(x);
}

function main() {
    const nmxy = readLine().split(' ').map(Number);
    const a = readLine().split(' ').map(Number);
    const b = readLine().split(' ').map(Number);

    const result = dressEmInVests(nmxy, a, b);
    printResult(result);
}

const dressEmInVests = (nmxy, a, b) => {
    let j = 0;
    let n = nmxy[0];
    let m = nmxy[1];
    let x = nmxy[2];
    let y = nmxy[3];
    let count = 0;
    let pairs = '';

    for (let i = 0; i < n; i++) {
        let min = a[i] - x;
        let max = a[i] + y;
        // console.log(i, a[i], min, max, j, b[j])
        while (j < m) {
            if (b[j] > max) {
                break;
            }
            if (b[j] >= min) {
                count++;
                pairs += `\n${i + 1} ${j + 1}`;
                j++;
                break;
            }
            j++;
        }
        if (j === m) break;
    }

    return `${count}${pairs}`;
};

var nmxy = readline().split(' ').map(Number);
var n = nmxy[0];
var m = nmxy[1];
var x = nmxy[2];
var y = nmxy[3];
var a = readline().split(' ').map(Number);
var b = readline().split(' ').map(Number);
var ans = [];
var i = 0;
var j = 0;
while (i<n){
    while (j<m){
		if (a[i]-x <= b[j] && b[j] <= a[i]+y) {
			ans.push(i+1, j+1);
			j++;
			break;
		}
		else break;
	}
	i++;
}
print (ans.length/2);
for (var k=0; k<ans.length; k=k+2){
	print (ans[k], ans[k+1]);
}

var nmxy = readline().split(' ').map(Number);
var n = nmxy[0];
var m = nmxy[1];
var x = nmxy[2];
var y = nmxy[3];
var a = readline().split(' ').map(Number);
var b = readline().split(' ').map(Number);
var ans = '';
var metka = 0;
next: for (var i=0; i<n; i++){
    for (var j=metka; j<m; j++){
		if (a[i]-x <= b[j] && b[j] <= a[i]+y) {
			ans = ans + (i+1) + (j+1);
			metka = j+1;
			continue next;
		}
	}
}
print (ans.length/2);
for (var k=0; k<ans.length; k=k+2){
	print (ans[k], ans[k+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()
function main() {
  const input = readline().split(' ')
  const [people, vests, reduction, increase] = input
  const desiredSizes = readline().split(' ').map(size => parseInt(size))
  const availableSizes = readline().split(' ').map(size => parseInt(size))

  helper(desiredSizes, availableSizes, reduction, increase)
}

function helper(desiredSizes, availableSizes, reduction, increase) {
    let result = []
    let currentSizeIndex = 0
    for (let i = 0; i < desiredSizes.length; i++) {
        if (availableSizes[currentSizeIndex] >= desiredSizes[i] - reduction && availableSizes[currentSizeIndex] <= desiredSizes[i] + increase) {
            result.push([i + 1, currentSizeIndex + 1])
            currentSizeIndex++
        }
    }

    console.log(result.length)
    result.forEach(r => console.log(r.join(' ')))
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const input = readline().split(' ')
  const [people, vests, reduction, increase] = input
  const desiredSizes = readline().split(' ').map(size => parseInt(size))
  const availableSizes = readline().split(' ').map(size => parseInt(size))

  helper(desiredSizes, availableSizes, parseInt(reduction), parseInt(increase))
}

function helper(desiredSizes, availableSizes, reduction, increase) {
    let result = []
    let currentSizeIndex = 0
    for (let i = 0; i < desiredSizes.length; i++) {
        if (availableSizes[currentSizeIndex] >= desiredSizes[i] - reduction && availableSizes[currentSizeIndex] <= desiredSizes[i] + increase) {
            result.push([i + 1, currentSizeIndex + 1])
            currentSizeIndex++
        }
    }

    console.log(result.length)
    result.forEach(r => console.log(r.join(' ')))
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const input = readline().split(' ')
  const [people, vests, reduction, increase] = input
  const desiredSizes = readline().split(' ').map(size => parseInt(size))
  const availableSizes = readline().split(' ').map(size => parseInt(size))

  helper(desiredSizes, availableSizes, parseInt(reduction), parseInt(increase))
}

function helper(desiredSizes, availableSizes, reduction, increase) {
    let result = []
    let currentSizeIndex = 0
    let count = 0
    let pairs = ''

    for (let i = 0; i < desiredSizes.length; i++) {
        let min = desiredSizes[i] - reduction
        let max = desiredSizes[i] + increase

        while (currentSizeIndex < availableSizes.length) {
            if (availableSizes[currentSizeIndex] > max) {
                break
            }

            if (availableSizes[currentSizeIndex] >= min) {
                count++;
                pairs += `\n${i + 1} ${currentSizeIndex + 1}`;
                currentSizeIndex++;
                break;
            }
            currentSizeIndex++;
        }

        if (currentSizeIndex === availableSizes.length) break;
    }

    return `${count}${pairs}`;
}

'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 input = readline().split(' ')
  const [people, vests, reduction, increase] = input
  const desiredSizes = readline().split(' ').map(size => parseInt(size))
  const availableSizes = readline().split(' ').map(size => parseInt(size))

  helper(desiredSizes, availableSizes, parseInt(reduction), parseInt(increase))
}

function helper(desiredSizes, availableSizes, reduction, increase) {
    let result = []
    let currentSizeIndex = 0
    for (let i = 0; i < desiredSizes.length; i++) {

        if (availableSizes[currentSizeIndex] >= desiredSizes[i] - reduction && availableSizes[currentSizeIndex] <= desiredSizes[i] + increase) {
            result.push([i + 1, currentSizeIndex + 1])
            currentSizeIndex++
        } else {
            while (desiredSizes[i] - reduction >= availableSizes[currentSizeIndex]) {
                currentSizeIndex++
            }
            if (availableSizes[currentSizeIndex] >= desiredSizes[i] - reduction && availableSizes[currentSizeIndex] <= desiredSizes[i] + increase) {
                result.push([i + 1, currentSizeIndex + 1])
                currentSizeIndex++
            }
        }

    }

    console.log(result.length)
    result.forEach(r => console.log(r.join(' ')))
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const input = readline().split(' ')
  const [people, vests, reduction, increase] = input
  const desiredSizes = readline().split(' ').map(size => parseInt(size))
  const availableSizes = readline().split(' ').map(size => parseInt(size))

  helper(desiredSizes, availableSizes, parseInt(reduction), parseInt(increase))
}

function helper(desiredSizes, availableSizes, reduction, increase) {
    let result = []
    let currentSizeIndex = 0
    for (let i = 0; i < desiredSizes.length; i++) {

        while (desiredSizes[i] - reduction >= availableSizes[currentSizeIndex]) {
            currentSizeIndex++
        }
        if (availableSizes[currentSizeIndex] >= desiredSizes[i] - reduction && availableSizes[currentSizeIndex] <= desiredSizes[i] + increase) {
            result.push([i + 1, currentSizeIndex + 1])
            currentSizeIndex++
        }

    }

    console.log(result.length)
    result.forEach(r=>console.log(r.join(' ')))
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function printResult(x) {
    process.stdout.write(x);
}

function main() {
    const nmxy = readLine().split(' ').map(Number);
    const a = readLine().split(' ').map(Number);
    const b = readLine().split(' ').map(Number);

    const result = dressEmInVests(nmxy, a, b);
    printResult(result);
}

const dressEmInVests = (nmxy, a, b) => {
    let j = 0;
    let n = nmxy[0];
    let m = nmxy[1];
    let x = nmxy[2];
    let y = nmxy[3];
    let count = 0;
    let pairs = '';

    for (let i = 0; i < n; i++) {
        let min = a[i] - x;
        let max = a[i] + y;
        while (j < m) {
            if (b[j] < min) {
                return `${count}\n${pairs}`;
            }
            if (b[j] > max) {
                break;
            } else {
                pairs = pairs + `${i + 1} ${j + 1}\n`;
                j++;
            }
        }
        if (j === m) break;
    }

    return `${count}\n${pairs}`;
};

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function printResult(x) {
    process.stdout.write(x);
}

function main() {
    const nmxy = readLine().split(' ').map(Number);
    const a = readLine().split(' ').map(Number);
    const b = readLine().split(' ').map(Number);

    const result = dressEmInVests(nmxy, a, b);
    printResult(result);
}

const dressEmInVests = (nmxy, a, b) => {
    let j = 0;
    let n = nmxy[0];
    let m = nmxy[1];
    let x = nmxy[2];
    let y = nmxy[3];
    let count = 0;
    let pairs = '';

    for (let i = 0; i < n; i++) {
        let min = a[i] - x;
        let max = a[i] + y;
        while (j < m) {
            if (b[j] < min) {
                return `${count}${pairs}`;
            }
            if (b[j] > max) {
                j++;
            } else {
                count++;
                pairs += `\n${i + 1} ${j + 1}`;
                j++;
                break;
            }
        }
        if (j === m) break;
    }

    return `${count}${pairs}`;
};

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function printResult(x) {
    process.stdout.write(x);
}

function main() {
    const nmxy = readLine().split(' ').map(Number);
    const a = readLine().split(' ').map(Number);
    const b = readLine().split(' ').map(Number);

    const result = dressEmInVests(nmxy, a, b);
    printResult(result);
}

const dressEmInVests = (nmxy, a, b) => {
    let j = 0;
    let n = nmxy[0];
    let m = nmxy[1];
    let x = nmxy[2];
    let y = nmxy[3];
    let count = 0;
    let pairs = '';

    for (let i = 0; i < n; i++) {
        let min = a[i] - x;
        let max = a[i] + y;
        while (j < m) {
            if (b[j] > max) {
                return `${count}${pairs}`;
            }
            if (b[j] >= min) {
                count++;
                pairs += `\n${i + 1} ${j + 1}`;
                j++;
                break;
            }
            j++;
        }
        if (j === m) break;
    }

    return `${count}${pairs}`;
};

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function printResult(x) {
    process.stdout.write(x);
}

function main() {
    const nmxy = readLine().split(' ').map(Number);
    const a = readLine().split(' ').map(Number);
    const b = readLine().split(' ').map(Number);

    const result = dressEmInVests(nmxy, a, b);
    printResult(result);
}

const dressEmInVests = (nmxy, a, b) => {
    let j = 0;
    let n = nmxy[0];
    let m = nmxy[1];
    let x = nmxy[2];
    let y = nmxy[3];
    let count = 0;
    let pairs = '';

    for (let i = 0; i < n; i++) {
        let min = a[i] - x;
        let max = a[i] + y;
        while (j < m) {
            if (b[j] < min) {
                return `${count}${pairs}`;
            }
            if (b[j] > max) {
                break;
            } else {
                count++;
                pairs += `\n${i + 1} ${j + 1}`;
                j++;
            }
        }
        if (j === m) break;
    }

    return `${count}${pairs}`;
};


'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const [n, a, b] = readline().split(' ').map(Number)
  const h = readline().split(' ').map(Number)

  helper(n, a, b, h)
}

function helper(n, a, b, h) {
    h.sort((a1,a2)=>a1 - a2)

    console.log((h[b] - h[b - 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++];
}

function printResult(x) {
    process.stdout.write(x);
}

function main() {
    const nmk = readLine().split(' ').map(Number);
    const arr = readLine().split(' ').map(Number);

    const result = chores(nmk[0],nmk[1],nmk[2],arr);
    printResult(result.toString());
}

const chores = (n, m, k, a) => {
    a.sort((x, y) => x - y);
    return a[k] - a[k-1] > 0 ? a[k] - a[k-1] : 0;
};

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, a, b] = d.split(' ').map(Number);
    return;
  }

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

  let boy1 = arr[a - 1];
  let boy2 = arr[a];

  console.log(boy1 - boy2);

  c++;
});

let data = '';
process.stdin.on('data',v => data += v);
const solution = () => {
	let line = data.split('\n');
	let [n, a, b] = line[0].split(' ').map(v => parseInt(v,10));
	let d = line[1].split(' ').map(v => parseInt(v,10));
	d.sort((a, b) => a - b);
	console.log(d[b] - d[b-1]);
	process.exit(0);
}

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const [n, a, b] = readline().split(' ').map(Number)
  const h = readline().split(' ').map(Number)

  helper(n, a, b, h)
}

function helper(n, a, b, h) {
    h.sort((a1,a2)=>a1 - a2)

    if (h[a + 1] !== h[a])
        console.log(h[a] + '')
    else
        console.log('0')
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const [n, a, b] = readline().split(' ').map(Number)
  const h = readline().split(' ').map(Number)

  helper(n, a, b, h)
}

function helper(n, a, b, h) {
    h.sort((a1,a2)=>a1 - a2)

    if (h[a - 1] !== h[a])
        console.log(h[a - 1])
    else
        console.log(0)
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const [n, a, b] = readline().split(' ').map(Number)
  const h = readline().split(' ').map(Number)

  helper(n, a, b, h)
}

function helper(n, a, b, h) {
    h.sort((a1,a2)=>a1 - a2)

    if (h[b] !== h[b - 1])
        console.log(h[b - 1] + '')
    else
        console.log('0')
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function printResult(x) {
    process.stdout.write(x);
}

function main() {
    const nmk = readLine().split(' ').map(Number);
    const arr = readLine().split(' ').map(Number);

    const result = chores(nmk[0],nmk[1],nmk[2],arr);
    printResult(result.toString());
}

const chores = (n, m, k, a) => {
    a.sort((x, y) => x - y);
    return a[k] - a[k-1] > 0 ? a[k-1] : 0;
};

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, a, b] = d.split(' ').map(Number);
    return;
  }

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

  if (arr[b] > b && arr[b -1] <= b) {
    console.log(arr[b] = arr[b - 1]);
  }
  else {
    console.log(0);
  }

  c++;
});


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

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

  if (obj[d]) {
    console.log('YES');
  }
  else {
    console.log('NO');
    obj[d] = true;
  }

  c++;
});

var n = parseInt(readline());
var names = {};

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

    if (names[name]) {
      print('YES');
    } else {
      names[name] = true;
      print('NO');
    }
}

function main(stdin) {
  const lines = stdin.split("\n");
  const before = new Set();
  lines.slice(1, 1 + parseInt(lines[0])).forEach(v => {
    console.log(before.has(v) ? "YES" : "NO");
    before.add(v);
  });
}

main(require("fs").readFileSync(0, "utf-8"));

//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↑入力 ↓出力');
	Main();
});
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 N = nextInt();
	var set = new Set();
	var output = new Array(N);
	for(var i = 0; i < N; i++){
		var s = next();
		if(set.has(s)){
			output[i] = "YES";
		}else{
			set.add(s);
			output[i] = "NO";
		}
	}
	myout(myconv(output, 9));
}

let input = [];

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

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

RL.on('close', () => {
    let n = parseInt(input[0]);

    let names = new Set();
    for(let i = 0; i < n; i++){
        if (names.has(input[i+1])) {
            console.log('YES');
        } else {
            console.log('NO');
        }
        names.add(input[i+1]);
    }
});

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

for(var i =0; i<n; i++){
   var flag=false;
   for (var j =0; j<i; j++){
   	if(array[j]===array[i]){
   		flag = true;
   	}
   }
   //print((flag):"YES"?"NO");
   if(flag === true)
   	print("YES");
   else
   	print("NO");
}

/**
 * Created by lukask on 9/24/17.
 */
var i;
var namesMap = {};
var streamLength = readline();
for (i = 0; i < streamLength; i++) {
  var entry = readline();
  if (namesMap[entry] === undefined) {
    print('NO');
    namesMap[entry] = true;
  } else {
    print('YES');
  }
}

var n = parseInt(readline());
var inpStr = "", data = [];
var i = 0, k = 0, m = 0;

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

  m = data.length;
  flag = 0;
  for(k=0;k<m;k++)
  {
    if(inpStr == data[k])
    {
      flag = 1;
    }
  }

  if(flag ==1)
  {
    print("YES");
  }
  else
  {
    print("NO");
    data.push(inpStr);
  }

}

(function() {
    'use strict';
    let n = readline();
    let y = [];
    for(let i = 0; i < n; i++) {
        let x = readline();
        y += x + ' ';
    }
    let z = y.split(' ').map(String);
    for (let i = 0; i < n; i++) {
    var re1 = new RegExp('\\b' + z[i] + '\\b');
    var re = new RegExp('\\b' + z[i] + '\\b', 'g');
    y = y.replace(re1, 'NO');
    y = y.replace(re, 'YES');
    }
    y = y.split(' ').map(String);
    for (let i = 0; i < n; i++) {
        print(y[i]);
    }
}());

var n = parseInt(readline());
var inpStr = "", data = [];
var i = 0, k = 0, m = 0;

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

  m = data.lenght;
  flag = 0;
  for(k=0;k<m;k++)
  {
    if(inpStr == data[k])
    {
      flag = 1;
    }
  }

  if(flag ==1)
  {
    print("YES");
  }
  else
  {
    print("NO");
    data.push(inpStr);
  }

}

(function() {
    'use strict';
    let n = readline();
    let y = [];
    for(let i = 0; i < n; i++) {
        let x = readline();
        y += x + ' ';
    }
    let z = y.split(' ').map(String);
    for (let i = 0; i < n; i++) {
    var re = new RegExp(z[i], 'g');
    y = y.replace(z[i], 'NO');
    y = y.replace(re, 'YES');
    }
    y = y.split(' ').map(String);
    for (let i = 0; i < n; i++) {
        print(y[i]);
    }
}());

function main(stdin) {
  const lines = stdin.split("\n");
  const before = new Set();
  lines.slice(1, 1 + parseInt(lines[0])).forEach(v => {
    console.log(before.has(v) ? "YES" : "NO");
    before.add(v);
  });
}

main(
  require("fs")
    .readFileSync(0, "utf-8")
    .trim()
);

function main(stdin) {
  const lines = stdin.split("\n");
  const before = new Set();
  lines.slice(1).forEach(v => {
    console.log(before.has(v) ? "YES" : "NO");
    before.add(v);
  });
}

main(
  require("fs")
    .readFileSync(0, "utf-8")
    .trim()
);


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 rowNum = integers[0], colNum = integers[1];

	var room = [];
	for (var r = 0; r < rowNum; r += 1) {
		room.push(trim(readline()));
	}

	function isClear(fromR, fromC, toR, toC) {
		for (var r = fromR; r <= toR; r += 1) {
			for (var c = fromC; c <= toC; c += 1) {
				if (room[r].charAt(c) == '1') {
					return false;
				}
			}
		}
		return true;
	}

	var bestPerimeter = 0;

	for (var fromR = 0; fromR < rowNum; fromR += 1) {
		for (var fromC = 0; fromC < colNum; fromC += 1) {
			for (var toR = fromR; toR < rowNum; toR += 1) {
				for (var toC = fromC; toC < colNum; toC += 1) {
					if (isClear(fromR, fromC, toR, toC)) {
						bestPerimeter = Math.max(bestPerimeter,
								2*(toR-fromR+1) + 2*(toC-fromC+1));
					}
				}
			}
		}
	}

	print(bestPerimeter);
}

main();

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))

const N = lll[0]
const M = lll[1]

const rm  = []

while (lll = readline()) {
  rm.push(lll.split('').map(v => parseInt(v)))
}

const pt = (rm, x, y) => {
  let xx = x
  let yy = y
  while (rm[yy][++xx] == 0) {}
  while (++yy < rm.length && rm[yy].slice(x, xx).reduce((e, c) => e || c, null) == 0) {}
  let p1 = 2 * (xx - x) + 2 * (yy - y)
  xx = x
  yy = y
  while (rm[yy + 1] && rm[++yy][xx] == 0) {}
  while(++xx < rm[0].length && rm.map(l => l[xx]).slice(y, yy).reduce((e, c) => e || c, null) == 0) {}
  let p2 = 2 * (xx - x) + 2 * (yy - y)
  return Math.max(p1, p2)
}

let max = 0

for (let i = 0; i < rm.length; i++) {
  for (let j = 0; j < rm[0].length; j++) {
    if (!rm[i][j]) max = Math.max(max, pt(rm, j, i))
  }
}

print(max)


function toi(x){return parseInt(x);}
(function(){
    var n=+readline();
    var s=0;
    for(var i=0;i<n;i++){
	var t=readline().split(" ").map(toi);
	s+=(t[2]-t[0]+1)*(t[3]-t[1]+1);
    }
    print(s);
})();

var n = +readline();
var input, x1, y1, x2, y2, cnt = 0;

for(i = 0; i < n; i++){
	input = readline().split(" ").map(Number);
	x1 = input[0], y1 = input[1], x2 = input[2], y2 = input[3];

	cnt += (Math.abs(x2 - x1) + 1) * (Math.abs(y2 - y1) + 1);
}

write(cnt);

// Code belogs to CyberZHG I am just testing something...
// http://codeforces.com/contest/552/submission/11679521

var n = parseInt(readline());
var ans = 0;
while (n--) {
    var nums = readline().split(' ').map(Number);
    ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);
}
print(ans);

function ProblemSolver() {
    this.HAS_TEST_CASES = false ;
    this.INPUT_FILE_NAME = "sample.in" ;
    this.OUTPUT_FILE_NAME = "sample.out" ;
    this.DO_OUTPUT_TO_FILE = false ;
    this.CLEAR_ARRAY_PER_CASE = true ;

    this.solveCase = function() {
        var res , i , j , fl , cn , a , b , c , d , k ;
        res = 0 ;
        for( i = 0 ; i < 4 * this.n ; i += 4 ) {
            a = this.arr[ i + 0 ] ;
            b = this.arr[ i + 1 ] ;
            c = this.arr[ i + 2 ] ;
            d = this.arr[ i + 3 ] ;
            for( j = a ; j <= c ; j++ ) {
                for( k = b ; k <= d ; k++ ) {
                    this.done[ j ][ k ]++ ;
                }
            }
        }
        for( j = 1 ; j <= 100 ; j++ ) {
            for( k = 1 ; k <= 100 ; k++ ) {
                res += this.done[ j ][ k ] ;
            }
        }
        print( res ) ;
    } ;

    this.init = function() {
        this.lim1 = 100010 ;
        this.lim2 = 110 ;
        this.cc = 1 ;
        this.ind = 1 ;
        this.n = 0 ;
        this.cn = 0 ;
        this.declareAndFillArrays() ;
    } ;

    this.getInput = function( irObj ) {
        var hasMoreInput , i ;
        hasMoreInput = true ;
        try {
        	this.n = irObj.nextInt() ;
            this.arr = [] ;
            for( i = 0 ; i < this.n ; i++ ) {
                this.arr.push( irObj.nextInt() ) ;
                this.arr.push( irObj.nextInt() ) ;
                this.arr.push( irObj.nextInt() ) ;
                this.arr.push( irObj.nextInt() ) ;
            }
        }
        catch( ex ) {
            hasMoreInput = false ;
        }
        return hasMoreInput ;
    } ;

    this.clearArraysPerCase = function() {
        var i , j ;
        this.arr = new Array() ;
        this.adjList = new Array() ;
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 ) ;
            this.adjList.push( new Array() ) ;
        }
        this.memo = new Array() ;
        this.done = new Array() ;
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() ) ;
            this.done.push( new Array() ) ;
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 ) ;
                this.done[ i ].push( 0 ) ;
            }
        }
    } ;

    this.clearPerCase = function() {
        this.cn = 0 ;
        this.cc++ ;
        if( this.CLEAR_ARRAY_PER_CASE == true ) {
            this.clearArraysPerCase() ;
        }
    } ;

    this.declareAndFillArrays = function() {
        var i , j ;
        this.srr = new Array() ;
        this.vis = new Array() ;
        this.arr = new Array() ;
        this.brr = new Array() ;
        this.memo = new Array() ;
        this.done = new Array() ;
        this.adjList = new Array() ;
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( '' ) ;
            this.vis.push( 0 ) ;
            this.arr.push( 0 ) ;
            this.brr.push( 0 ) ;
            this.adjList.push( new Array() ) ;
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() ) ;
            this.done.push( new Array() ) ;
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 ) ;
                this.done[ i ].push( 0 ) ;
            }
        }
    } ;

    this.init() ;
}

function InputReader() {
    var self = this ;
    this.allLines = new Array() ;
    this.currrentLineNumber = 0 ;
    this.currrentCharacterIndex = 0 ;
    this.callBackFunction = null ;
    this.parentContext = null ;

    this.readAllLines = function() {
        var singleLine ;
        while( true ) {
            try {
                singleLine = readline() ;
                if( singleLine == null ) {
                    break ;
                }
            }
            catch( ex ) {
                break ;
            }
            this.allLines.push( singleLine ) ;
        }
    } ;

    this.readAllLinesFromRhino = function() {
        var brObj , line ;
        importPackage( java.io ) ;
        importPackage( java.lang ) ;
        brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;
        this.allLines = [] ;
        while( true ) {
            line = brObj.readLine() ;
            if( line == null ) {
                break;
            }
            this.allLines.push( line ) ;
        }
    } ;

    this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {
        self.chunkData += chunk ;
    } ;

    this.readEndFromNodeJsJudgeServer = function() {
        self.parseRawData( self.chunkData ) ;
        self.parentContext.runCases() ;
    } ;

    this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {
        this.parentContext = parentContext ;
        process.stdin.resume() ;
        process.stdin.setEncoding( 'utf8' ) ;
        this.chunkData = '' ;
        process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;
        process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;
    } ;

    this.parseRawData = function( data ) {
        var len , i , currentString ;
        len = data.length ;
        currentString = '' ;
        this.allLines = [] ;
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString ) ;
                currentString = '' ;
            }
            else {
                currentString += data[ i ] ;
            }
        }
        if( currentString != '' ) {
            this.allLines.push( currentString ) ;
        }
    } ;

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData ;
        fsObj = require( 'fs' ) ;
        currentDirectory = __dirname ;
        if( currentDirectory.indexOf( 'D:' ) != -1 ) {
            //on windows
            inputFilePath = currentDirectory + '\\' + inputFileName ;
        }
        else {
            //on linux
            inputFilePath = currentDirectory + '/' + inputFileName ;
        }
        rawData = fsObj.readFileSync( inputFilePath , "utf8" ) ;
        this.parseRawData( rawData ) ;
    } ;

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx ;
        if( flag == 0 ) {
            if( this.currrentCharacterIndex != 0 ) {
                this.currrentLineNumber++ ;
                this.currrentCharacterIndex = 0 ;
            }
            res = '' ;
            len = this.allLines[ this.currrentLineNumber ].length ;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
            }
            this.currrentLineNumber++ ;
            this.currrentCharacterIndex = 0 ;
            return res ;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( 'No more tokens available!' ) ;
            }
            startIdx = -1 ;
            len = this.allLines[ this.currrentLineNumber ].length ;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {
                    startIdx = i ;
                    break ;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++ ;
                this.currrentCharacterIndex = 0 ;
                continue ;
            }
            res = '' ;
            endIdx = len - 1 ;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {
                    endIdx = i ;
                    break ;
                }
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {
                    res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;
                }
                else {
                    res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
                }
            }
            this.currrentCharacterIndex = endIdx ;
            if( endIdx == len - 1 ) {
                this.currrentLineNumber++ ;
                this.currrentCharacterIndex = 0 ;
            }
            return res ;
        }
    } ;

    this.nextInt = function() {
        return parseInt( this.next( 1 ) ) ;
    } ;

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) ) ;
    } ;

    this.nextString = function() {
        return this.next( 1 ) ;
    } ;

    this.nextLine = function() {
        return this.next( 0 ) ;
    } ;
}

function FileOutputHandler() {
    this.resultantStringArray = new Array() ;

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString ) ;
    } ;

    this.clearPercase = function() {
        this.resultantStringArray = new Array() ;
    } ;

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath ;
        res = '' ;
        sz = this.resultantStringArray.length ;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += '\n' ;
            }
            res += this.resultantStringArray[ i ] ;
        }
        fsObj = require( 'fs' ) ;
        currentDirectory = __dirname ;
        if( currentDirectory.indexOf( 'D:' ) != -1 ) {
            //on windows
            outputFilePath = currentDirectory + '\\' + outputFileName ;
        }
        else {
            //on linux
            outputFilePath = currentDirectory + '/' + outputFileName ;
        }
        fsObj.writeFileSync( outputFilePath , res ) ;
        this.clearPercase() ;
    } ;
}

function CodeExecutioner() {
    this.irObj = new InputReader() ;
    this.psObj = new ProblemSolver() ;
    this.fohObj = new FileOutputHandler() ;

    this.runCases = function() {
		var testCases , hasMoreTestCases , i ;
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt() ;
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase() ;
                this.psObj.getInput( this.irObj ) ;
                this.psObj.solveCase() ;
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase() ;
                hasMoreTestCases = this.psObj.getInput( this.irObj ) ;
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase() ;
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;
        }
    } ;

    this.detectEnvironmentType = function() {
        var environmentType = null ;
        try {
            if( importPackage != null ) {
                environmentType = 'rhino' ;
            }
        }
        catch( ex1 ) {
            try {
                //for nodejs local server check
                if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {
                    environmentType = 'local-node-js' ;
                }
                else {
                    environmentType = 'server-node-js' ;
                }
            }
            catch( ex2 ) {
                try {
                    if( readline == null || typeof( readline ) != 'function' ) {
                        environmentType = 'server-node-js' ;
                    }
                    else {
                        try {
                            if( Map != null ) {
                                environmentType = 'spider-monkey' ;
                            }
                            else {
                                environmentType = 'javascript-v8' ;
                            }
                        }
                        catch( ex3 ) {
                            environmentType = 'javascript-v8' ;
                        }
                    }
                }
                catch( ex3 ) {
                    environmentType = 'server-node-js' ;
                }
            }
        }
        return environmentType ;
    } ;

    this.configureStreamsAndReadInput = function() {
        var localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log ;
                }
            }
            catch( ex ) {
                print = console.log ;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj ;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments ) ;
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log ;
                }
            }
            catch( ex ) {
                print = console.log ;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines() ;
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino() ;
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines() ;
            this.runCases() ;
        }
    } ;

    this.configureStreamsAndReadInput() ;
}

new CodeExecutioner() ;


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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

function main() {
  var t = parseInt(readline())

while(t--){
    var s = readline()
    var x = s.split(' ')
    var a = parseInt(x[0])
    var b = parseInt(x[1])
    var str = ''
    var flag = false
    while(a>0 || b>0){
        if(flag === false && a>0){
            str+='0'
            if(b>0) flag = true
            a--
        }
        else if(flag === true && b>0){
            str+='1'
            if(a>0) flag = false
            b--
        }
    }
    console.log(str)
}

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function output(x) {
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

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

    for (let i = 0; i < N; i++) {
        let [zeros, ones] = readline().split(' ').map(Number);

        let min = Math.min(zeros, ones);
        let max = Math.max(zeros, ones);
        let diff = max - min;
        let moreOf = zeros > ones ? '0': '1';

        let result = ('01').repeat(min);
        result += moreOf.repeat(diff);

        output(result);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function 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() {
    const cases = readline();

    for (let i = 0; i < cases; i++) {
        const n = readline();
        let [zeros, ones] = n.split(' ').map(Number);
        let max = Math.max(zeros, ones);
        let min = Math.min(zeros, ones);
        let rep = zeros > ones ? '01' : '10';
        let suff = zeros > ones ? '0' : '1';
        let result = rep.repeat(min);
        result = result + suff.repeat(max - min);
        output(result);
    }
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
	var t = lines[0];
	var n = 0;
	for(i = 1; i <= t; i++){
        var k = lines[i].split(' ').map(Number);
        var x = k[0], y = k[1];
        var ans = '';
        while(x !== 0 && y !== 0){
            ans += '01';
            x--;
            y--;
        }
        while(x !== 0){
            ans += '0';
            x--;
        }
        while(y !== 0){
            ans += '1';
            y--;
        }
        console.log(ans);
    }
});

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}
var T = readline();
for(var qe=1;qe<=T;qe++) {
  //var n = readline()//.split(' ').map((x) => parseInt(x));
  var [a, b] = readline().split(' ').map((x) => parseInt(x));
  var ans = '';
  if(a>=b){
       for(var i=0;i<b;i++){
            ans+="01";
       }
       for(var i=0;i<a-b;i++){
            ans+="0";
       }
  }
  else{
        for(var i=0;i<a;i++){
            ans+="10";
       }
       for(var i=0;i<b-a;i++){
            ans+="1";
       }
  }

  console.log(ans)

}

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

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

var T = readline();
for(var qe=1;qe<=T;qe++) {
  //var n = readline()//.split(' ').map((x) => parseInt(x));
  var [a, b] = readline().split(' ').map((x) => parseInt(x));
  var ans = '';
  var x = a, j = b;
  var iNext = false, jNext = true;
  for(var i=0;i<(a+b);i++) {
    if(iNext) {
      if(x > 0) {
        x--;
        ans += 0;
        iNext = false;
        jNext = true;
        continue;
      }
    }
    if(jNext) {
      if(j > 0) {
        j--;
        ans += 1;
        iNext = true;
        jNext = false;
        continue;
      }
    }
    if(x > 0) {
      x--
      ans += 0;
      continue;
    }
    if(j > 0) {
      j--;
      ans += 1;
    }
  }

  console.log(ans)
  //fs.appendFileSync('output.txt', ans+'\r\n');

}
//

'use strict';

function solve(n, m) {
  let res = [];
  const a = Math.min(n, m);
  for (let i = 0; i < a * 2; i += 2) {
    if (n > m) res[i] = 0, res[i + 1] = 1;else res[i] = 1, res[i + 1] = 0;
  }
  n -= a;
  m -= a;
  if (n) {
    while (n--) {
      res.push(0);
    }
  } else if (m) {
    while (m--) {
      res.push(1);
    }
  }
  return res.join('');
}

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

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

//@ts-check
/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine() {
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace("\r", "");
}

function print(x) {
    console.log(x);
}

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine()
        .split(" ")
        .map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function add(   a   ,b){
    let k = a+b;
    return k;
}

function solve() {
    let t = readSingleInt();
    const boundary = `**********`;
    while (t--) {
        let [a,b] = readIntArray();

        let d = Math.min(a,b);
        let ans ='';
        for(let i=0;i<d;i++){
            ans+="01";
        }
        let chr ;
        if(a>b){
            chr='0';
        }else{
            chr='1'
        }
        for(let i=0;i<Math.abs(a-b);i++){
            ans+=chr;
        }
       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++];
}

function output(x) {
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

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

    for (let i = 0; i < N; i++) {
        let [zeros, ones] = readline().split(' ');

        let min = Math.min(zeros, ones);
        let max = Math.max(zeros, ones);
        let diff = max - min;
        let moreOf = zeros > ones ? '0': '1';

        let result = ('01').repeat(min);
        result += moreOf.repeat(diff);

        output(result);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function output(x) {
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

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

    for (let i = 0; i < N; i++) {
        let [zeros, ones] = readline().split(' ');

        let min = Math.min(zeros, ones);
        let max = Math.max(zeros, ones);
        let diff = max - min;
        let base = zeros > ones ? '01' : '10';
        let moreOf = zeros > ones ? '0': '1';

        let result = base.repeat(min);
        result += moreOf.repeat(diff);

        output(result);
    }
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
	var t = lines[0];
    var k = lines[1].split('');
	var cnt = 0;
	var ans = '';
	var a = new Array(10);
	for(i = 0; i < 10; i++){
	    a[i] = 0;
	}
	for(i = 0; i < t; i++){
        if(k[i] == 'L'){
            cnt = 0;
            for(j = 0; j < 10; j++){
                if(a[j] === 0){
                    cnt++;
                    a[j] = 1;
                }
                if(cnt == 1){
                    break;
                }
            }
        }else if(k[i] =='R'){
            cnt = 0;
            for(j = 9; j >= 0; j--){
                if(a[j] === 0){
                    cnt++;
                    a[j] = 1;
                }
                if(cnt == 1){
                    break;
                }
            }
        }else{
            a[k[i]] = 0;
        }
	}
	for(i = 0; i < 10; i++){
	    ans += a[i];
	}
	console.log(ans);
});

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}
var T = readline();
for(var qe=1;qe<=T;qe++) {
  //var n = readline()//.split(' ').map((x) => parseInt(x));
  var [a, b] = readline().split(' ').map((x) => parseInt(x));
  var ans = '';
  if(a>=b){
       for(var i=0;i<b;i++){
            ans+="01";
       }
       for(var i=0;i<a-b;i++){
            ans+="0";
       }
  }
  else{
        for(var i=0;i<a;i++){
            ans+="10";
       }
       for(var i=0;i<a-b;i++){
            ans+="1";
       }
  }

  console.log(ans)

}

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

function main() {
  var t = parseInt(readline())

  while(t--){
    var s = readline()
    var x = s.split(' ')
    var a = parseInt(x[0])
    var b = parseInt(x[1])
    var str = ''
    while(a--) str+='0'
    while(b--) str+='1'
    console.log(str)
  }

}

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

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

var T = readline();
for(var qe=1;qe<=T;qe++) {
  //var n = readline()//.split(' ').map((x) => parseInt(x));
  var [a, b] = readline().split(' ').map((x) => parseInt(x));
  var ans = '';
  var i = a, j = b;
  var iNext = false, jNext = true;
  while(i>0 || j>0) {
    if(iNext || j == 0) {
      ans += 0
      jNext = true;
      iNext = false;
      i--
      continue;
    }
    if(jNext || i == 0) {
      ans += 1
      j--
      jNext = false;
      iNext = true
    }
  }

  console.log(ans)
  //fs.appendFileSync('output.txt', ans+'\r\n');

}
//