Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer $$$x$$$ as nearly prime if it can be represented as $$$p \cdot q$$$, where $$$1 < p < q$$$ and $$$p$$$ and $$$q$$$ are prime numbers. For example, integers $$$6$$$ and $$$10$$$ are nearly primes (since $$$2 \cdot 3 = 6$$$ and $$$2 \cdot 5 = 10$$$), but integers $$$1$$$, $$$3$$$, $$$4$$$, $$$16$$$, $$$17$$$ or $$$44$$$ are not.Captain Flint guessed an integer $$$n$$$ and asked you: can you represent it as the sum of $$$4$$$ different positive integers where at least $$$3$$$ of them should be nearly prime.Uncle Bogdan easily solved the task and joined the crew. Can you do the same?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ lines contain test cases — one per line. The first and only line of each test case contains the single integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^5)$$$ — the number Flint guessed.

For each test case print:    YES and $$$4$$$ different positive integers such that at least $$$3$$$ of them are nearly prime and their sum is equal to $$$n$$$ (if there are multiple answers print any of them);  NO if there is no way to represent $$$n$$$ as the sum of $$$4$$$ different positive integers where at least $$$3$$$ of them are nearly prime.  YES NO

NoteIn the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.In the third test case, $$$n=31=2 \cdot 7 + 2 \cdot 5 + 2 \cdot 3 + 1$$$: integers $$$14$$$, $$$10$$$, $$$6$$$ are nearly prime.In the fourth test case, $$$n=36=5 + 2 \cdot 3 + 2 \cdot 5 + 3 \cdot 5$$$: integers $$$6$$$, $$$10$$$, $$$15$$$ are nearly prime.In the fifth test case, $$$n=44=2 \cdot 3 + 7 + 2 \cdot 5 + 3 \cdot 7$$$: integers $$$6$$$, $$$10$$$, $$$21$$$ are nearly prime.In the sixth test case, $$$n=100=2 + 2 \cdot 5 + 3 \cdot 11 + 5 \cdot 11$$$: integers $$$10$$$, $$$33$$$, $$$55$$$ are nearly prime.In the seventh test case, $$$n=258=2 \cdot 5 + 3 \cdot 7 + 13 \cdot 17 + 2 \cdot 3$$$: integers $$$10$$$, $$$21$$$, $$$221$$$, $$$6$$$ are nearly prime.

//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 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 output = [];
  for(var i = 0; i < N; i++){
    var a = nextInt();
    if(a < 31){
      output.push("NO");
    }else{
      output.push("YES");
      if(a == 36){
        output.push("6 10 15 5");
      }else if(a == 40){
        output.push("6 14 15 5");
      }else if(a == 44){
        output.push("6 10 15 13");
      }else{
        output.push("6 10 14 " + (a - 30));
      }
    }
  }
  myout(myconv(output, 9));
}

var read = require('readline').createInterface({
   input: process.stdin
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
   obj = init(inLine);
   var start = Date.now();
   Main();
   console.error("\n");
   var end = Date.now() - start;
   myerr("time : " + (end) + "ms");
   myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function input(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
    var returnObj = {
      list : input, index : 0, max : input.length,
      hasNext : function(){return (this.index < this.max);},
      next : function(){
        if(!this.hasNext()){

            throw "ArrayIndexOutOfBoundsException これ以上ないよ";
        }
        else{
            var returnInput = this.list[this.index];
            this.index++;
            return returnInput;
        }
    }};
    return returnObj;
}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
function puts(s){console.log(s);}
function print(s) {process.stdout.write(s+"");}

function Main(){
    tc = parseInt(input())
    while(tc--) {

        k = parseInt(input())
        s = 6+10+14
        arr = [6,10,14]
        if(k <= s) {
            puts("NO")
        }
        else {
            e = k - s
            z = "6 10 14 "
            if(arr.indexOf(e) !== -1) {
                z = "6 10 15 "
                e -= 1
            }
            puts("YES")
            puts(z+e)
        }
    }
}

start()

async function start() {
    const input = await readArgs()
    const numOfTests = input[0]
    for (let i = 1; i < numOfTests + 1; i++) {
        const num = input[i]
        const res = sol(num)
        output(res)
    }
}

function output(arr) {
    if (arr.length == 0) console.log('NO')
    else {
        console.log('YES')
        console.log(`${arr[0]} ${arr[1]} ${arr[2]} ${arr[3]}`)

    }
}

function sol(n) {
    switch (n) {
        case 36:
            return [6,10,15,5]
        case 40:
            return [6, 14, 15, 5]
        case 44:
            return [6, 10, 15, 13]
        default:
            return n < 31 ? [] : [6, 10, 14, n - 30]
    }
}

function readArgs() {
    let i = ''
    process.stdin.on('data', c => i += c)
    return new Promise(res => {
        process.stdin.on('end', () => {
            const { EOL } = require('os')
            let lines = i.split(EOL)
            // lines = lines.map(line => line.split(' '))
            lines = lines.map(line => parseInt(line))
            res(lines)
        })
    })
}

var read = require('readline').createInterface({
   input: process.stdin
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
   obj = init(inLine);
   var start = Date.now();
   Main();
   console.error("\n");
   var end = Date.now() - start;
   myerr("time : " + (end) + "ms");
   myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function input(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
    var returnObj = {
      list : input, index : 0, max : input.length,
      hasNext : function(){return (this.index < this.max);},
      next : function(){
        if(!this.hasNext()){

            throw "ArrayIndexOutOfBoundsException これ以上ないよ";
        }
        else{
            var returnInput = this.list[this.index];
            this.index++;
            return returnInput;
        }
    }};
    return returnObj;
}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
function puts(s){console.log(s);}
function print(s) {process.stdout.write(s+"");}

function Main(){
    tc = parseInt(input())
    while(tc--) {

        k = parseInt(input())
        s = 6+10+14
        arr = [6,10,14]
        if(k < s) {
            puts("NO")
        }
        else {
            e = k - s
            z = "6 10 14 "
            if(arr.indexOf(e) !== -1) {
                z = "6 10 15 "
                e -= 1
            }
            puts("YES")
            puts(z+e)
        }
    }
}

var read = require('readline').createInterface({
   input: process.stdin
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
   obj = init(inLine);
   var start = Date.now();
   Main();
   console.error("\n");
   var end = Date.now() - start;
   myerr("time : " + (end) + "ms");
   myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function input(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
    var returnObj = {
      list : input, index : 0, max : input.length,
      hasNext : function(){return (this.index < this.max);},
      next : function(){
        if(!this.hasNext()){

            throw "ArrayIndexOutOfBoundsException これ以上ないよ";
        }
        else{
            var returnInput = this.list[this.index];
            this.index++;
            return returnInput;
        }
    }};
    return returnObj;
}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
function puts(s){console.log(s);}
function print(s) {process.stdout.write(s+"");}

function Main(){
    tc = parseInt(input())
    while(tc--) {

        k = parseInt(input())
        s = 6+10+14
        if(k < s) {
            puts("NO")
        }
        else {
            e = k - s
            puts("YES")
            puts("6 10 14 "+e)
        }
    }
}

start()

async function start() {
    const input = await readArgs()
    const numOfTests = input[0]
    for (let i = 1; i < numOfTests + 1; i++) {
        const num = input[i]
        const res = sol(num)
        output(res)
    }
}

function output(arr) {
    if (arr.length == 0) console.log('NO')
    else {
        console.log('YES')
        console.log(`${arr[0]} ${arr[1]} ${arr[2]} ${arr[3]}`)

    }
}

function sol(n) {
    switch (n) {
        case 36:
            return [6,10,15,5]
        case 40:
            return [6, 14, 15, 5]
        case 44:
            return [6, 10, 15, 13]
        default:
            return n < 30 ? [] : [6, 10, 14, n - 30]
    }
}

function readArgs() {
    let i = ''
    process.stdin.on('data', c => i += c)
    return new Promise(res => {
        process.stdin.on('end', () => {
            const { EOL } = require('os')
            let lines = i.split(EOL)
            // lines = lines.map(line => line.split(' '))
            lines = lines.map(line => parseInt(line))
            res(lines)
        })
    })
}

start()

async function start() {
    const input = await readArgs()
    const numOfTests = input[0]
    for (let i = 1; i < numOfTests + 1; i++) {
        const num = input[i]
        const res = sol(num)
        output(res)
    }
}

function output(arr) {
    if (arr.length == 0) console.log('NO')
    else {
        console.log('YES')
        console.log(`${arr[0]} ${arr[1]} ${arr[2]} ${arr[3]}`)

    }
}

function sol(n) {
    return n < 30 ? [] : [6, 10, 14, n - 30]
}

function readArgs() {
    let i = ''
    process.stdin.on('data', c => i += c)
    return new Promise(res => {
        process.stdin.on('end', () => {
            const { EOL } = require('os')
            let lines = i.split(EOL)
            // lines = lines.map(line => line.split(' '))
            lines = lines.map(line => parseInt(line))
            res(lines)
        })
    })
}


Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007.

The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students.

Print the minimum total time to finish all tasks modulo 10 007.

NoteIn the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.

var n = parseInt(readline())
a = []
for (var i = 0; i < n; i++) {
    a.push(parseInt(readline()))
}
a.sort(function(x, y) {
    return x - y
})
ans = 0
for (var i = 0; i < n; i++) {
    ans += a[i] * a[n - 1 - i]
    ans %= 10007
}
print(ans)

var n = parseInt(readline())
a = []
for (var i = 0; i < n; i++) {
    a.push(parseInt(readline()))
}
a.sort()
ans = 0
for (var i = 0; i < n; i++) {
    ans += a[i] * a[n - 1 - i]
    ans %= 10007
}
print(ans)


City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them.Sand roads have long been recognized out of date, so the decision was made to asphalt them. To do this, a team of workers was hired and a schedule of work was made, according to which the intersections should be asphalted.Road repairs are planned for n2 days. On the i-th day of the team arrives at the i-th intersection in the list and if none of the two roads that form the intersection were already asphalted they asphalt both roads. Otherwise, the team leaves the intersection, without doing anything with the roads.According to the schedule of road works tell in which days at least one road will be asphalted.

The first line contains integer n (1 ≤ n ≤ 50) — the number of vertical and horizontal roads in the city.  Next n2 lines contain the order of intersections in the schedule. The i-th of them contains two numbers hi, vi (1 ≤ hi, vi ≤ n), separated by a space, and meaning that the intersection that goes i-th in the timetable is at the intersection of the hi-th horizontal and vi-th vertical roads. It is guaranteed that all the intersections in the timetable are distinct.

In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.

NoteIn the sample the brigade acts like that:  On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road;  On the second day the brigade of the workers comes to the intersection of the 1-st horizontal and the 2-nd vertical road. The 2-nd vertical road hasn't been asphalted, but as the 1-st horizontal road has been asphalted on the first day, the workers leave and do not asphalt anything;  On the third day the brigade of the workers come to the intersection of the 2-nd horizontal and the 1-st vertical road. The 2-nd horizontal road hasn't been asphalted but as the 1-st vertical road has been asphalted on the first day, the workers leave and do not asphalt anything;  On the fourth day the brigade come to the intersection formed by the intersection of the 2-nd horizontal and 2-nd vertical road. As none of them has been asphalted, the workers asphalt the 2-nd vertical and the 2-nd horizontal road.

var n = +readline(), h = [], v = [];

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

for(var i = 0; i < (n*n); i++){
	input = readline().split(" ").map(Number);
	a = input[0] - 1;
	b = input[1] - 1;

	if(h[a] == false && v[b] == false){
		h[a] = true;
		v[b] = true;

		write((i+1) + " ");
	}
}

'use strict';

// let inpFileStrArr = `
// 2
// 1 1
// 1 2
// 2 1
// 2 2
// `.trim().split('\n').map(x => x.trim()), inpFileCounter = 0;
// function readline() {
//   return inpFileStrArr[inpFileCounter++];
// }
// function print(x) {
//   console.log(x);
// }

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var n = Number(readline()),
    h = [],
    v = [],
    res = [];
for (var i = 0; i < n; i++) {
  h.push(false);v.push(false);
}
h.unshift(0);v.unshift(0);

for (var i = 0; i < n * n; i++) {
  var _readline$split$map = readline().split(' ').map(Number);

  var _readline$split$map2 = _slicedToArray(_readline$split$map, 2);

  var _h = _readline$split$map2[0];
  var _v = _readline$split$map2[1];

  if (!h[_h] && !v[_v]) {
    res.push(i + 1);
    h[_h] = true;v[_v] = true;
  }
}
res.sort(function (a, b) {
  return a - b;
});
print(res.join(' '));

/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};

/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {

/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;

/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};

/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;

/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}

/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;

/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;

/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";

/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	var List = __webpack_require__(1);
	var n = List.map(parseInt, readline().split(' '))[0];
	var markedX = List.create(n, false);
	var markedY = List.create(n, false);
	var result = [];
	for (var i = 0; i < n * n; i++) {
	    var _a = List.map(parseInt, readline().split(' ')), x = _a[0], y = _a[1];
	    if (!markedX[x - 1] && !markedY[y - 1]) {
	        markedX[x - 1] = true;
	        markedY[y - 1] = true;
	        result.push(i + 1);
	    }
	}
	print(result.join(' '));

/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

	var Prelude_1 = __webpack_require__(2);
	function add(xs, ys) {
	    return xs.concat(ys);
	}
	exports.add = add;
	function head(xs) {
	    return xs[0];
	}
	exports.head = head;
	function last(xs) {
	    return xs[xs.length - 1];
	}
	exports.last = last;
	function tail(xs) {
	    return xs.slice(1);
	}
	exports.tail = tail;
	function init(xs) {
	    return xs.slice(0, xs.length - 1);
	}
	exports.init = init;
	function map(f, xs) {
	    var result = new Array(xs.length);
	    for (var i = 0; i < xs.length; i++) {
	        result[i] = f(xs[i]);
	    }
	    return result;
	}
	exports.map = map;
	function reverse(xs) {
	    return xs.slice().reverse();
	}
	exports.reverse = reverse;
	function intersperse(x, xs) {
	    if (xs.length == 0) {
	        return [];
	    }
	    var result = new Array(xs.length + xs.length - 1);
	    for (var i = 0; i + 1 < xs.length; i++) {
	        result[i + i] = xs[i];
	        result[i + i + 1] = x;
	    }
	    result[result.length - 1] = xs[xs.length - 1];
	    return result;
	}
	exports.intersperse = intersperse;
	function intercalate(xs, xss) {
	    return concat(intersperse(xs, xss));
	}
	exports.intercalate = intercalate;
	function foldl(f, initial, xs) {
	    var result = initial;
	    for (var i = 0; i < xs.length; i++) {
	        result = f(result, xs[i]);
	    }
	    return result;
	}
	exports.foldl = foldl;
	function foldr(f, initial, xs) {
	    var result = initial;
	    for (var i = xs.length - 1; i >= 0; i--) {
	        result = f(xs[i], result);
	    }
	    return result;
	}
	exports.foldr = foldr;
	function concat(xss) {
	    var total = sum(map(function (xs) { return xs.length; }, xss));
	    var result = new Array(total);
	    var m = 0;
	    for (var i = 0; i < xss.length; i++) {
	        var xs = xss[i];
	        for (var j = 0; j < xs.length; j++) {
	            result[m++] = xs[j];
	        }
	    }
	    return result;
	}
	exports.concat = concat;
	function sum(xs) {
	    var result = 0;
	    for (var i = 0; i < xs.length; i++) {
	        result += xs[i];
	    }
	    return result;
	}
	exports.sum = sum;
	function product(xs) {
	    var result = 1;
	    for (var i = 0; i < xs.length; i++) {
	        result *= xs[i];
	    }
	    return result;
	}
	exports.product = product;
	function sort(xs, compare) {
	    return copy(xs).sort(compare);
	}
	exports.sort = sort;
	function sortInPlace(xs, compare) {
	    xs.sort(compare);
	    return xs;
	}
	exports.sortInPlace = sortInPlace;
	function maximumInRange(xs, s, e) {
	    var result = xs[s];
	    for (var i = s + 1; i <= e; i++) {
	        if (result < xs[i])
	            result = xs[i];
	    }
	    return result;
	}
	exports.maximumInRange = maximumInRange;
	function maximum(xs) {
	    return maximumInRange(xs, 0, xs.length - 1);
	}
	exports.maximum = maximum;
	function maximumInRangeWith(xs, s, e, f) {
	    var result = f(xs[s]);
	    for (var i = s + 1; i <= e; i++) {
	        var candidate = f(xs[i]);
	        if (result < candidate)
	            result = candidate;
	    }
	    return result;
	}
	exports.maximumInRangeWith = maximumInRangeWith;
	function maximumWith(xs, f) {
	    return maximumInRangeWith(xs, 0, xs.length - 1, f);
	}
	exports.maximumWith = maximumWith;
	function minimumInRange(xs, s, e) {
	    var result = xs[s];
	    for (var i = s + 1; i <= e; i++) {
	        if (result > xs[i])
	            result = xs[i];
	    }
	    return result;
	}
	exports.minimumInRange = minimumInRange;
	function minimum(xs) {
	    return minimumInRange(xs, 0, xs.length - 1);
	}
	exports.minimum = minimum;
	function minimumInRangeWith(xs, s, e, f) {
	    var result = f(xs[s]);
	    for (var i = s + 1; i <= e; i++) {
	        var candidate = f(xs[i]);
	        if (result > candidate)
	            result = candidate;
	    }
	    return result;
	}
	exports.minimumInRangeWith = minimumInRangeWith;
	function minimumWith(xs, f) {
	    return minimumInRangeWith(xs, 0, xs.length - 1, f);
	}
	exports.minimumWith = minimumWith;
	function replicate(n, x) {
	    var result = new Array(n);
	    for (var i = 0; i < result.length; i++) {
	        result[i] = x;
	    }
	    return result;
	}
	exports.replicate = replicate;
	function take(n, xs) {
	    return xs.slice(0, n);
	}
	exports.take = take;
	function drop(n, xs) {
	    return xs.slice(n);
	}
	exports.drop = drop;
	function splitAt(n, xs) {
	    return [take(n, xs), drop(n, xs)];
	}
	exports.splitAt = splitAt;
	function takeWhile(f, xs) {
	    for (var i = 0; i < xs.length; i++) {
	        if (!f(xs[i])) {
	            return xs.slice(0, i);
	        }
	    }
	    return xs.slice();
	}
	exports.takeWhile = takeWhile;
	function dropWhile(f, xs) {
	    for (var i = 0; i < xs.length; i++) {
	        if (!f(xs[i])) {
	            return xs.slice(i);
	        }
	    }
	    return [];
	}
	exports.dropWhile = dropWhile;
	function group(xs) {
	    if (xs.length == 0)
	        return [];
	    var result = [];
	    var last = [xs[0]];
	    for (var i = 1; i < xs.length; i++) {
	        if (last[0] === xs[i]) {
	            last.push(xs[i]);
	        }
	        else {
	            result.push(last);
	            last = [xs[i]];
	        }
	    }
	    result.push(last);
	    return result;
	}
	exports.group = group;
	function nub(xs) {
	    if (xs.length == 0)
	        return [];
	    var result = [];
	    result.push(xs[0]);
	    for (var i = 1; i < xs.length; i++) {
	        if (xs[i] !== xs[i - 1]) {
	            result.push(xs[i]);
	        }
	    }
	    return result;
	}
	exports.nub = nub;
	function filter(f, xs) {
	    var result = [];
	    for (var i = 0; i < xs.length; i++) {
	        if (f(xs[i]))
	            result.push(xs[i]);
	    }
	    return result;
	}
	exports.filter = filter;
	function zip(xs, ys) {
	    var n = Prelude_1.min(xs.length, ys.length);
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = [xs[i], ys[i]];
	    }
	    return result;
	}
	exports.zip = zip;
	function unzip(xs) {
	    var r1 = new Array(xs.length);
	    var r2 = new Array(xs.length);
	    for (var i = 0; i < xs.length; i++) {
	        r1[i] = xs[i][0];
	        r2[i] = xs[i][1];
	    }
	    return [r1, r2];
	}
	exports.unzip = unzip;
	function range(from, to) {
	    var result = Array(to - from + 1);
	    for (var i = from; i <= to; i++) {
	        result[i - from] = i;
	    }
	    return result;
	}
	exports.range = range;
	function copy(xs) {
	    return xs.slice(0);
	}
	exports.copy = copy;
	function apply_permutation(p, xs) {
	    var n = xs.length;
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = xs[p[i]];
	    }
	    return result;
	}
	exports.apply_permutation = apply_permutation;
	function next_permutation(p) {
	    var n = p.length;
	    if (n < 2)
	        return null;
	    var r = copy(p);
	    var k = n - 2;
	    for (; k >= 0 && r[k] >= r[k + 1]; k--)
	        ;
	    if (k < 0)
	        return null;
	    for (var i = k + 1, j = n - 1; i < j; i++, j--) {
	        var t_1 = r[i];
	        r[i] = r[j];
	        r[j] = t_1;
	    }
	    var next = k + 1;
	    for (; r[next] <= r[k]; next++)
	        ;
	    var t = r[k];
	    r[k] = r[next];
	    r[next] = t;
	    return r;
	}
	exports.next_permutation = next_permutation;
	function create(n, value) {
	    return replicate(n, value);
	}
	exports.create = create;
	function createWith(n, f) {
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = f(i);
	    }
	    return result;
	}
	exports.createWith = createWith;
	function create2D(n1, n2, value) {
	    return map(function (_) { return replicate(n2, value); }, replicate(n1, 0));
	}
	exports.create2D = create2D;
	function create2DWith(n1, n2, f) {
	    var result = new Array(n1);
	    for (var i = 0; i < n1; i++) {
	        result[i] = new Array(n2);
	        for (var j = 0; j < n2; j++) {
	            result[i][j] = f(i, j);
	        }
	    }
	    return result;
	}
	exports.create2DWith = create2DWith;

/***/ },
/* 2 */
/***/ function(module, exports) {

	function min(a, b) {
	    return a < b ? a : b;
	}
	exports.min = min;
	function max(a, b) {
	    return a < b ? b : a;
	}
	exports.max = max;
	function curry(f) {
	    return function (x) { return function (y) { return f(x, y); }; };
	}
	exports.curry = curry;
	function uncurry(f) {
	    return function (x, y) { return f(x)(y); };
	}
	exports.uncurry = uncurry;
	function id(x) {
	    return x;
	}
	exports.id = id;
	function constant(x) {
	    return function (_) { return x; };
	}
	exports.constant = constant;
	function flip(f) {
	    return function (y) { return function (x) { return f(x)(y); }; };
	}
	exports.flip = flip;
	function flip2(f) {
	    return function (y, x) { return f(x, y); };
	}
	exports.flip2 = flip2;
	function compose(g, f) {
	    return function (x) { return g(f(x)); };
	}
	exports.compose = compose;
	function gcd(a, b) {
	    var r = a % b;
	    while (r !== 0) {
	        a = b;
	        b = r;
	        r = a % b;
	    }
	    return b;
	}
	exports.gcd = gcd;

/***/ }
/******/ ]);

'use strict';

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

//code

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var n = Number(readline()),
    result = [];
var rows = [],
    cols = [];
for (var i = 1; i <= n * n; i++) {
	var _readline$split = readline().split(' ');

	var _readline$split2 = _slicedToArray(_readline$split, 2);

	var a = _readline$split2[0];
	var b = _readline$split2[1];

	if (rows.indexOf(a) === -1 && cols.indexOf(b) === -1) {
		result.push(i);
		rows.push(a);
		cols.push(b);
	}
}
print(result.join(' '));

'use strict';

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

//code

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var n = Number(readline()),
    result = [];
for (var i = 1; i <= n * n; i++) {
	var _readline$split = readline().split(' ');

	var _readline$split2 = _slicedToArray(_readline$split, 2);

	var a = _readline$split2[0];
	var b = _readline$split2[1];

	if (a === b) {
		result.push(i);
	}
}
print(result.join(' '));


It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor.Doctors have a strange working schedule. The doctor i goes to work on the si-th day and works every di day. So, he works on days si, si + di, si + 2di, ....The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors?

First line contains an integer n — number of doctors (1 ≤ n ≤ 1000).  Next n lines contain two numbers si and di (1 ≤ si, di ≤ 1000).

Output a single integer — the minimum day at which Borya can visit the last doctor.

NoteIn the first sample case, Borya can visit all doctors on days 2, 3 and 4.In the second sample case, Borya can visit all doctors on days 10 and 11.

var n=readline();
var s=[];
var i=0;
var mindays=0,temp,days1,days;
while(n)
{
 s[i] = readline();
 i++;
 n--;
}
for(temp of s)
{
   var days=parseInt(temp.split(" ")[0]);
   var altdays=parseInt(temp.split(" ")[1]);
    if(mindays<days)
    {
        mindays=days;
    }
    else{
    while(mindays>=days)
    days=days+altdays;
    mindays=days
}
}
print(mindays);

var n = +readline();
var t = 0;
for (var i = 0; i < n; i++) {
    var line = readline().split(" ");
    var s = +line[0], d = +line[1];
    t++;
    while (t < s || t % d !== s % d) {
        t++;
    }
}
print(t);

var n=readline();
var s=[];
var i=0;
var mindays=0,temp,days1,days;
while(n)
{
 s[i] = readline();
 i++;
 n--;
}
for(temp of s)
{
   var days=parseInt(temp.split(" ")[0]);
   var altdays=parseInt(temp.split(" ")[1]);
    days<mindays?mindays=days+altdays:mindays=days;
}
print(mindays);


There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately. In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct). In the first contest, the participant on the 100-th place scored $$$a$$$ points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least $$$b$$$ points in the second contest.Similarly, for the second contest, the participant on the 100-th place has $$$c$$$ points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least $$$d$$$ points in the first contest.After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.Given integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$, please help the jury determine the smallest possible value of the cutoff score.

You need to process $$$t$$$ test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 3025$$$) — the number of test cases. Then descriptions of $$$t$$$ test cases follow. The first line of each test case contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$0 \le a,\,b,\,c,\,d \le 9$$$; $$$d \leq a$$$; $$$b \leq c$$$).  One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.

For each test case print a single integer — the smallest possible cutoff score in some olympiad scenario satisfying the given information.

NoteFor the first test case, consider the following olympiad scenario: there are $$$101$$$ participants in the elimination stage, each having $$$1$$$ point for the first contest and $$$2$$$ points for the second contest. Hence the total score of the participant on the 100-th place is $$$3$$$.For the second test case, consider the following olympiad scenario:   there are $$$50$$$ participants with points $$$5$$$ and $$$9$$$ for the first and second contest respectively;  $$$50$$$ participants with points $$$4$$$ and $$$8$$$ for the first and second contest respectively;  and $$$50$$$ participants with points $$$2$$$ and $$$9$$$ for the first and second contest respectively.  Hence the total point score of the participant on the 100-th place is $$$12$$$.

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

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

function main() {
  let t = +readLine();
  while (t--) {
    const [a, b, c, d] = readLine().split(" ").map(Number);

    console.log(Math.max(a + b, c + d));
  }
}

var fs = require("fs");

var buffer = fs.readFileSync(0);

var arr = buffer.toString().split("\n").map(val => val.trim());

let t = +arr[0];

for(var i = 1; i <= t; i++)
{
    let nums = arr[i].split(" ").map(val => Number(val));
    console.log(Math.max(nums[0]+nums[1], nums[2]+nums[3]));
}

var fs = require("fs");

var buffer = fs.readFileSync(0);

var arr = buffer.toString().split("\n").map(val => val.trim());

let t = +arr[0];

let out = "";
for(var i = 1; i <= t; i++)
{
    let nums = arr[i].split(" ").map(val => Number(val));
    out += Math.max(nums[0]+nums[1], nums[2]+nums[3]).toString() + "\n";
}
console.log(out);

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

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

// import './array'
//
// import io from './io'
//
// function main() {
//   let [a, b, c, d] = io.nextNumbers()
//
//   io.puts(Math.max(a + b, c + d))
// }
//
// io.runEachTest(main)
// // io.runMain(main)

let input = ''

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

process.stdin.on('end', () => {
  input.trim().split('\n').slice(1).forEach((line) => {
    const [a, b, c, d] = line.split(' ').map((x) => parseInt(x))
    console.log(Math.max(a + b, c + d))
  })
})

var inputs = parseInt(readline());

for(var i =0;i<inputs;i++)
{
	var params = readline().split(" ").map(x => parseInt(x));

	if((params[0]+params[2] < params[0]+params[1]) || (params[0]+params[2] < params[2]+params[3]))
	{
	    print(params[0]+params[2])
	}
	else
	{
	    if((params[0]+params[1] )> (params[2]+params[3]))
	    {
	        print(params[0]+params[1])
	    }
	    else
	    {
	      print(  params[2]+params[3])
	    }
	}
}

var fs = require("fs");

var buffer = fs.readFileSync(0);

var arr = buffer.toString().split("\n").map(val => val.trim());

let t = +arr[0][0];

for(var i = 1; i <= t; i++)
{
    let nums = arr[i].split(" ").map(val => Number(val));
    console.log(Math.max(nums[0]+nums[1], nums[2]+nums[3]));
}

var fs = require("fs");

var buffer = fs.readFileSync(0);

var arr = buffer.toString().split("\n").map(val => val.trim());

let t = +arr[0][0];

for(var i = 1; i < arr.length; i++)
{
    let nums = arr[i].split(" ").map(val => Number(val));
    console.log(Math.max(nums[0]+nums[1], nums[2]+nums[3]));
}


Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.There will be n columns participating in the parade, the i-th column consists of li soldiers, who start to march from left leg, and ri soldiers, who start to march from right leg.The beauty of the parade is calculated by the following formula: if L is the total number of soldiers on the parade who start to march from the left leg, and R is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal |L - R|.No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index i and swap values li and ri. Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty.

The first line contains single integer n (1 ≤ n ≤ 105) — the number of columns.  The next n lines contain the pairs of integers li and ri (1 ≤ li, ri ≤ 500) — the number of soldiers in the i-th column which start to march from the left or the right leg respectively.

Print single integer k — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached. Consider that columns are numbered from 1 to n in the order they are given in the input data. If there are several answers, print any of them.

NoteIn the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal 5 + 8 + 3 = 16, and who march from the right leg — 6 + 9 + 10 = 25. In this case the beauty equals |16 - 25| = 9.It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9.

function readIntTabLine() {
  var l = readline().split(' ')
  for (var i = 0 ; i < l.length ; i++) {
    l[i] = parseInt(l[i])
  }
  return l
}

var n = parseInt(readline()), // n columns
    cols = [],
    beauty = 0

for (var i = 0 ; i < n ; i++) {
  cols[i] = readIntTabLine() // li left leg, ri right leg
  cols[i][2] = cols[i][0] - cols[i][1]
  beauty += cols[i][2]
}

var max = 0,
    ans = -1

for (var i = 0 ; i < n ; i++) {
  var mod = Math.abs(beauty - 2*cols[i][2]) - Math.abs(beauty)
  if (mod > max) {
    max = mod
    ans = i
  }
}

print(ans+1)

var N = Number(readline());
var arr = [];
var toread = [];
var score_a = [];
var total = 0;
for (var i = 0;i < N;i ++) {
	toread = readline().split(' ');
	arr.push({
		s: Number(toread[0]),
		e: Number(toread[1])
	});
	score_a.push(arr[i].s - arr[i].e);
	total += score_a[i];
};

var max = Math.abs(total);
var z_total = z(total);
var rs = 0;
for (var i = 0;i < score_a.length;i ++) {
	var tmp_max = Math.abs(total - 2 * score_a[i]);
	if (tmp_max > max) {
		rs = i + 1;
		max = tmp_max;
	}
}

print(rs);

function z(_a) {
	var a = Math.abs(_a);
	return a == _a;
}

var n = +readline();
var arr = [], l = 0, r = 0;
for (var i = 0; i < n; i++) {
    var input = readline().split(' ').map(Number);
    l += input[0];
    r += input[1];
    arr.push(input)
}
var max = Math.abs(l - r), k = 0;
arr.forEach((el, i) => {
    var curr_val = Math.abs(l - r - 2 * el[0] + 2 * el[1]);
    if (max < curr_val) {
        max = curr_val;
        k = i + 1
    }
});

print(k);

var n = +readline();
var arr = [], l = 0, r = 0;
for (var i = 0; i < n; i++) {
    var input = readline().split(' ').map(Number);
    l += input[0];
    r += input[1];
    arr.push(2 * (input[0] - input[1]))
}
var max = Math.abs(l - r), k = 0;
arr.forEach((el, i) => {
    var curr_val = Math.abs(l - r - el);
    if (max < curr_val) {
        max = curr_val;
        k = i + 1
    }
});

print(k);

var n = +readline();
var arr = [], l = 0, r = 0;
for (var i = 0; i < n; i++) {
    var input = readline().split(' ').map(Number);
    l += input[0];
    r += input[1];
    arr.push(input)
}
var max = Math.abs(l - r);
var k = 0;
for (var i = 0; i < n; i++) {
    var el = arr[i];
    if (max < Math.abs(l - el[0] + el[1] - r + el[1] - el[0])) {
        max = Math.abs(l - el[0] + el[1] - r + el[1] - el[0]);
        k = i + 1
    }
}

print(k);


Given an undirected connected graph with $$$n$$$ vertices and $$$m$$$ edges. The graph contains no loops (edges from a vertex to itself) and multiple edges (i.e. no more than one edge between each pair of vertices). The vertices of the graph are numbered from $$$1$$$ to $$$n$$$. Find the number of paths from a vertex $$$s$$$ to $$$t$$$ whose length differs from the shortest path from $$$s$$$ to $$$t$$$ by no more than $$$1$$$. It is necessary to consider all suitable paths, even if they pass through the same vertex or edge more than once (i.e. they are not simple).    Graph consisting of $$$6$$$ of vertices and $$$8$$$ of edges For example, let $$$n = 6$$$, $$$m = 8$$$, $$$s = 6$$$ and $$$t = 1$$$, and let the graph look like the figure above. Then the length of the shortest path from $$$s$$$ to $$$t$$$ is $$$1$$$. Consider all paths whose length is at most $$$1 + 1 = 2$$$.   $$$6 \rightarrow 1$$$. The length of the path is $$$1$$$.  $$$6 \rightarrow 4 \rightarrow 1$$$. Path length is $$$2$$$.  $$$6 \rightarrow 2 \rightarrow 1$$$. Path length is $$$2$$$.  $$$6 \rightarrow 5 \rightarrow 1$$$. Path length is $$$2$$$. There is a total of $$$4$$$ of matching paths.

The first line of test contains the number $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. Before each test case, there is a blank line.  The first line of test case contains two numbers $$$n, m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le 2 \cdot 10^5$$$) —the number of vertices and edges in the graph.  The second line contains two numbers $$$s$$$ and $$$t$$$ ($$$1 \le s, t \le n$$$, $$$s \neq t$$$) —the numbers of the start and end vertices of the path. The following $$$m$$$ lines contain descriptions of edges: the $$$i$$$th line contains two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \le u_i,v_i \le n$$$) — the numbers of vertices that connect the $$$i$$$th edge. It is guaranteed that the graph is connected and does not contain loops and multiple edges. It is guaranteed that the sum of values $$$n$$$ on all test cases of input data does not exceed $$$2 \cdot 10^5$$$. Similarly, it is guaranteed that the sum of values $$$m$$$ on all test cases of input data does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single number — the number of paths from $$$s$$$ to $$$t$$$ such that their length differs from the length of the shortest path by no more than $$$1$$$. Since this number may be too large, output it modulo $$$10^9 + 7$$$.

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        l++
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        const [src, dst] = lines[l++].trim().split(' ').map(Number)
        const edges = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))
        l += m
        output[i] = solve(n, m, src, dst, edges)
    }
    console.log(output.join('\n'))
// })()
})
class Queue {
    constructor() {
        this.map = {}
        this.first = 0
        this.last = 0
    }
    push(val) {
        this.map[this.last++] = val
    }
    shift() {
        const r = this.map[this.first]
        delete this.map[this.first]
        this.first++
        return r
    }
    size() {
        if (this.first >= this.last) return 0
        return this.last - this.first
    }
}
function solve(n, m, s, t, edges) {
    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })

    // const q = [[s, 0, 0]]
    const q = new Queue()
    q.push([s, 0, 0])
    const dist = [Array(n + 1).fill(Infinity), Array(n + 1).fill(Infinity)] // distance
    const count = [Array(n + 1).fill(0), Array(n + 1).fill(0)] // ways
    const visited = [Array(n + 1).fill(0), Array(n + 1).fill(0)] // ways
    dist[0][s] = 0
    count[0][s] = 1
    let md = Infinity
    // while (q.length) {
    while (q.size()) {
    // console.log(q.slice(0, 10))
        const [u, d, c] = q.shift()
        if (visited[c][u]) continue
        visited[c][u] = 1
        if (u === t) {
            if (c === 0) md = d
            if (c === 1) break
        }
        if (d >= md + 1) continue
        const nd = d + 1
        const nc = count[c][u]
        //
        ;(adj[u] || []).forEach(v => {
            if (nd < dist[0][v]) {
                if (dist[1][v] !== Infinity) {
                    dist[1][v] = dist[0][v]
                    if (dist[1][v] <= nd + 1) {
                        count[1][v] = count[0][v]
                        // q.push([v, dist[1][v], 1])
                        push(q, visited, v, dist[1][v], 1)
                    } else {
                        dist[1][v] = Infinity
                    }
                }
                dist[0][v] = nd
                count[0][v] = nc
                // q.push([v, nd, 0])
                push(q, visited, v, nd, 0)
            } else if (nd === dist[0][v]) {
                count[0][v] = add(count[0][v], nc)
            } else if (nd < dist[1][v]) {
                dist[1][v] = nd
                if (dist[1][v] <= dist[0][v] + 1) {
                    count[1][v] = nc
                    // q.push([v, nd, 1])
                    push(q, visited, v, nd, 1)
                } else {
                    dist[1][v] = Infinity
                }
            } else if (nd === dist[1][v]) {
                count[1][v] = add(count[1][v], nc)
            }
        })
    }
// console.log(dist)
// console.log(count)
    if (dist[1][t] === dist[0][t] + 1) {
        return add(count[0][t], count[1][t])
    } else {
        return count[0][t]
    }
}
function push(q, visited, u, d, c) {
    if (visited[c][u]) return
    q.push([u, d, c])
}
function add(a, b) {
    return (a + b) % (1e9 + 7)
}

'use strict';
const { throws } = require('assert');

 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const l = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;

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

const EPS = 1e-6;
const MOD = 1e9+7;

class Graph {
  constructor(){
    this.g = {};
  }
  add(a, b){
    if (!this.g[a])
      this.g[a] = [];
    this.g[a].push(b);
  }
  bfs(s, t){
    let counts = {};
    counts[s] = {0: 1};
    let paths_count = {[s]: 1};
    let queue = [], qi = 0;
    let min_path;
    l('GRAPH')
    queue.push([s, 0]);
    while (qi<queue.length){
      let [node, len] = queue[qi++];
      let to_nodes = this.g[node]||[];
      let cur_cnt = counts[node][len];
      for (let to of to_nodes){
        if (!counts[to])
          counts[to] = {};
        if (!counts[to][len+1]){
          if ((paths_count[to]||0)<3){
            queue.push([to, len+1]);
          }
          paths_count[to] = (paths_count[to]||0)+1;
          counts[to][len+1] = 0;
        }
        if (to==t && min_path===undefined)
          min_path = len+1;
        counts[to][len+1] = (counts[to][len+1]+cur_cnt)%MOD; // MOD
      }
    }
    l('RES', counts, paths_count)
    return (counts[t][min_path]+(counts[t][min_path+1]||0))%MOD;
  }
}

const calc = (graph, s, t)=>{
  return graph.bfs(s, t);
};

function main() {
    let T = +readline()
    while (T--){
      readline()
      let [n, m] = ra();
      let [s, t] = ra();
      s--; t--;
      let graph = new Graph();
      for (let i=0; i<m; i++){
        let [a, b] = ra();
        a--;
        b--;
        graph.add(a, b);
        graph.add(b, a);
      }
      print(calc(graph, s, t));
    }
}

E.calc = calc;

'use strict';
const { throws } = require('assert');

 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const l = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;

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

const EPS = 1e-6;

class Graph {
  constructor(){
    this.g = {};
  }
  add(a, b){
    if (!this.g[a])
      this.g[a] = [];
    this.g[a].push(b);
  }
  bfs(s, t){
    let counts = {};
    counts[s] = {0: 1};
    let queue = [], qi = 0;
    let min_path;
    l('GRAPH')
    queue.push([s, 0]);
    while (qi<queue.length){
      let [node, len] = queue[qi++];
      let to_nodes = this.g[node]||[];
      let cur_cnt = counts[node][len];
      for (let to of to_nodes){
        if (!counts[to])
          counts[to] = {};
        if (!counts[to][len+1]){
          if (Object.keys(counts[to]).length<3)
            queue.push([to, len+1]);
          counts[to][len+1] = 0;
        }
        if (to==t && min_path===undefined)
          min_path = len+1;
        counts[to][len+1] += cur_cnt; // MOD
      }
    }
    l('RES', counts)
    return counts[t][min_path]+(counts[t][min_path+1]||0)
  }
}

const calc = (graph, s, t)=>{
  return graph.bfs(s, t);
};

function main() {
    let T = +readline()
    while (T--){
      readline()
      let [n, m] = ra();
      let [s, t] = ra();
      s--; t--;
      let graph = new Graph();
      for (let i=0; i<m; i++){
        let [a, b] = ra();
        a--;
        b--;
        graph.add(a, b);
        graph.add(b, a);
      }
      print(calc(graph, s, t));
    }
}

E.calc = calc;


Let's define a multiplication operation between a string $$$a$$$ and a positive integer $$$x$$$: $$$a \cdot x$$$ is the string that is a result of writing $$$x$$$ copies of $$$a$$$ one after another. For example, "abc" $$$\cdot~2~=$$$ "abcabc", "a" $$$\cdot~5~=$$$ "aaaaa".A string $$$a$$$ is divisible by another string $$$b$$$ if there exists an integer $$$x$$$ such that $$$b \cdot x = a$$$. For example, "abababab" is divisible by "ab", but is not divisible by "ababab" or "aa".LCM of two strings $$$s$$$ and $$$t$$$ (defined as $$$LCM(s, t)$$$) is the shortest non-empty string that is divisible by both $$$s$$$ and $$$t$$$.You are given two strings $$$s$$$ and $$$t$$$. Find $$$LCM(s, t)$$$ or report that it does not exist. It can be shown that if $$$LCM(s, t)$$$ exists, it is unique.

The first line contains one integer $$$q$$$ ($$$1 \le q \le 2000$$$) — the number of test cases. Each test case consists of two lines, containing strings $$$s$$$ and $$$t$$$ ($$$1 \le |s|, |t| \le 20$$$). Each character in each of these strings is either 'a' or 'b'.

For each test case, print $$$LCM(s, t)$$$ if it exists; otherwise, print -1. It can be shown that if $$$LCM(s, t)$$$ exists, it is unique.

NoteIn the first test case, "baba" = "baba" $$$\cdot~1~=$$$ "ba" $$$\cdot~2$$$.In the second test case, "aaaaaa" = "aa" $$$\cdot~3~=$$$ "aaa" $$$\cdot~2$$$.

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 998244353n
var maxN = 10e6 + 1

function main() {
  var x = parseInt(readline())
  //

  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    var a = readline()
    var b = readline()
    var s = a
    if (a.length > b.length) {
      a = b
      b = s
    }

    var ss = ''
    for (let i = 0; i < a.length; i++) {
      ss += a[i]
      if (a.length % ss.length === 0 && ss.repeat(a.length / ss.length) === a &&
        b.length % ss.length === 0 && ss.repeat(b.length / ss.length) === b
      ) {
        var len = ss.length
        var count = 1
        while (len % a.length !== 0 || len % b.length !== 0) {
          count++
          len += ss.length
        }
        // console.log(ss, count, len, len % a.length !== 0, len % b.length !== 0)
        console.log(ss.repeat(count))
        return
      }
    }
    console.log(-1)

  })

}

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

  return gcd(b, a % b);
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  const LCM = (n1, n2) => {
    let i = 1,
      t = n1;
    while (n1 % n2 !== 0) {
      n1 = t * i;
      i++;
    }
    return n1;
  };
  while (t--) {
    let str1 = readline().trim().split("");
    let str2 = readline().trim().split("");
    let len = LCM(str1.length, str2.length);
    let n1 = [],
      n2 = [];
    for (let i = 0; i < len; i++) n1.push(str1[i % str1.length]);
    for (let i = 0; i < len; i++) n2.push(str2[i % str2.length]);
    let ans = true;
    for (let i = 0; i < len; i++) {
      if (n1[i] !== n2[i]) {
        ans = false;
        break;
      }
    }
    console.log(`${ans === true ? n1.join("") : -1}`);
  }
};
solve();

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

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

function main() {
	let t = +readLine();
	while (t--) {
		const s1 = readLine();
		const s2 = readLine();
		let [small, large] = ['', ''];
		if (s1 < s2) {
			[small, large] = [s1, s2];
		} else {
			[small, large] = [s2, s1];
		}
		const [smallLen, largeLen] = [small.length, large.length];
		if (largeLen % smallLen === 0) {
			if (small.repeat(largeLen / smallLen) === large) console.log(large);
			else console.log(-1);
		} else {
			let len = Math.floor((smallLen * largeLen) / gcd(smallLen, largeLen));
			if (small.repeat(len / smallLen) === large.repeat(len / largeLen)) {
				console.log(small.repeat(len / smallLen));
			} else console.log(-1);
		}
	}
}

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

let lines = []

const createReadLine = () => {
  i = 0;
  return () => lines[i++]
}

rl.on('line', line => lines.push(line))

function divided(a, b) {
  return a.split(b).join('').length ? false : true;
}

function gcd(a, b) {
	if (!a || !b) return 0

	while (true) {
		if ((a %= b) === 0)
			return Math.abs(b);
		else if ((b %= a) === 0)
			return Math.abs(a);
  }
}

rl.on("close", () => {
  const readLine = createReadLine();
  let t = parseInt(readLine());
  while (t--) {
    let a = readLine(),
        b = readLine()

    const lcm = (a.length * b.length / gcd(a.length, b.length))

    if (a.length < b.length) [a, b] = [b, a]
    const str = b.repeat(lcm / b.length)

    if (divided(str, a) && divided(str, b)) {
      console.log(str)
    }
    else {
      console.log(-1)
    }
  }
});

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

//Don't have to see. end------------------------------------------

function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var A = next();
		var B = next();
		var l = lcm(A.length, B.length);
		var nA = new Array(l / A.length).fill(A).join("");
		var nB = new Array(l / B.length).fill(B).join("");
		if(nA == nB){
			myout(nA);
		}else{
			myout(-1);
		}
	}
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

'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() {
  let testCases = readline()
  while(testCases--)
    solve()
}

// function to solve problems
function solve (){
  let firstWord = readline()
  let secondWord = readline()
  let smallWord = '', largeWord = '', ans = ''
  // ====== SOLUTION ======
  // console.log(`Firstword = ${firstWord} | secondWord = ${secondWord}`)
  if (firstWord.length < secondWord.length) {
    smallWord = firstWord
    largeWord = secondWord
  } else {
    largeWord = firstWord
    smallWord = secondWord
  }
  if (!isCompleteSubstring(smallWord, largeWord)) {
    console.log(-1)
    return
  }
  // get length from here
  const smallWordLength = smallWord.length
  const largeWordLength = largeWord.length

  const lcm = (largeWordLength * smallWordLength)/gcd(smallWordLength, largeWordLength)
  // console.log(`lcm = ${lcm}`)
  let factor = lcm/largeWordLength
  // ans = largeWord
  while (factor--) {
    ans += largeWord
  }
  console.log(ans)
}

function isCompleteSubstring(smallWord, largeWord) {
  if (!largeWord.includes(smallWord))
    return false

  let newWord = largeWord + smallWord
  smallWord += largeWord
  // console.log(`SmallWOr =  ${smallWord} | largeWord = ${newWord}`)
  if (smallWord !== newWord)
    return false
  return true
}
function gcd(a, b) {
  // console.log(`a = ${a}, b = ${b}`)
  if(a == 0)
    return b
  return gcd(b % a, a)
}

const readline = require("readline");
const leScan = readline.createInterface({
	input: process.stdin,
	output: process.stdout
	//terminal: false
});

toggle = true;
i1 = 0;
leScan.on("line", (input) => {
	if (i1 == 0)
	{
		i1 = 3; //Ok we went over i1
		return;
	}

	if (toggle)
	{
		i1 = input;
		toggle = false;
	}
	else
	{
		console.log(lcm(i1, input));
		toggle = true;
	}
});

const lcm = (s1, s2) => {
	let s1Construct = s1;
	let s2Construct = s2;

	/*//Makes sure a GCF actually exists or the LCM will never exist lmao
	if (findGCF(s1, s2) == -1)
	{
		return -1;
	}*/

	while (s1Construct != s2Construct)
	{
		if (s1Construct.length < s2Construct.length)
		{
			s1Construct += s1;
		}
		else if (s1Construct.length == s2Construct.length) //If it's equal, then it means we're hopeless and a LCM does not exist
		{
			return -1;
		}
		else //if s2Construct.length < s1Construct.length
		{
			s2Construct += s2;
		}
	}

	return s1Construct;
}

/*const cm = (str) => {
	let gcf = "";
	let currchain = "";

	for (var i=0; i < str.length; i++)
	{
		currchain += str[i];

		var currdex = currchain.length - 1;

		//Checks if the currchain matches the gcf (% accounts for repeats). If it doesn't, we know the gcf + currChain is the cm
		if (currchain[currdex] != gcf[currdex % gcf.length])
		{
			gcf += currchain;
			currchain = "";
		}
	}

	//Returns the gcf and the number of times the gcf repeats in the string. Should be an int if a gcf exists
	return [gcf, str.length / gcf.length];
}

const lcm = (s1, s2) => {
	if (s2.length < s1.length)
	{
		var temp = s2;
		s2 = s1; //convience purposes lol
		s1 = temp;
	}

	let gcf = findGCF(s1, s2);

	if (gcf == -1)
	{
		return -1;
	}
	else
	{
		//Modify s1 until it matches s2 using the gcf

		while (s1 != s2)
		{

		}
	}
}*/

const findGCF = (s1, s2) => {
	if (s2.length < s1.length)
	{
		var temp = s2;
		s2 = s1; //convience purposes lol
		s1 = temp;
	}

	//Modified Euler GCF formula lmao
	//But this is easier as last index will be remainder
	//tracker keeps track of how many times we have splitted s2
	var arr = s2.split(s1);
	var gcf = arr[0];
	var remainder = arr[arr.length - 1];

	//If the function did not make the gcf length less, then we know that it's hopeless and we should just return -1
	if (gcf.length == s2.length)
	{
		return -1;
	}

	//When gcf == remainder, the remainder is "0"
	return gcf == remainder ? gcf : findGCF(gcf, remainder);
}

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

const calculate = (a, b) => {
  if (a < b) {
    const temp = a
    a = b
    b = temp
  }

  let tempA = a
  let tempB = b

  while (tempA.length !== tempB.length) {
    if (tempA.length > tempB.length) {
      tempB += b
    } else {
      tempA += a
    }
  }

  return tempA === tempB ? tempA : -1
}

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

let a, b
let answer = []

readline.on('line', line => {
  if (index === -1) {
    maxRound = Number(line)
    index = 0
  } else {
    const mode = index % 2
    if (mode === 0) {
      a = line
    } else if (mode === 1) {
      b = line
      answer.push(calculate(a, b))
      round++
      if (round === maxRound) {
        readline.close()
        console.log(answer.join('\n'))
        return
      }
    }
    index++
  }
})

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

const gcd = (a, b) => {
  while (b) {
    const w = b;
    b = a % b;
    a = w;
  }
  return a;
};

const lcm = (s, t) => {
  const length = Math.floor((s.length * t.length) / gcd(s.length, t.length));
  s = s.repeat(Math.floor(length / s.length));
  t = t.repeat(Math.floor(length / t.length));
  if (s === t) return s;
  return -1;
};

const main = () => {
  let test = parseInt(readline());
  while (test--) {
    const s = readline();
    const t = readline();
    console.log(lcm(s, t));
  }
};

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 => string.trim());
  main();
});

const readline = () => {
  return inputString[currentLine++];
};

/*
 * File Created: Thursday, 14th January 2021 3:54:21 pm
 * Author: Lukas Rimkus
 */

'use-strict'

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

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(readLine(), 10);

    while(testCases--) {

        const s = readLine();

        const t = readLine();

        const res = b(s,t);

        console.log(res);
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function a(n, d, arr){

    arr.sort((a,b) => a - b);
    // console.log(arr)
    for(let i = 0; i < n ; i++){
        if(arr[i] <= d) continue;
        if(arr[i] > d){
            if(arr[0] + arr[1] <= d && i !== 0 && i !== 1 ){
                continue;
            }
            if(i === 0){
                if(arr[1] + arr[2] <= d) continue;
            }
            if(i === 1){
                if(arr[0] + arr[2] <= d) continue;
            }
        }
        return 'NO'
    }
    return 'YES'
}

function gcd(a,b){
    if(b === 0) return a;
    else{
        return gcd(b, a % b)
    }
}

function lcm(a,b){
    return (a * b) / gcd(a,b)
}

function mul(s, k) {
    let res = '';
    while(k--) res += s;
    return res;
}

function b(s,t){
    const n = s.length;
    const m = t.length;
    const g = gcd(n,m);
    // console.log('gcd(n,m) = ',g,'mul(s,m/g) = ', mul(s, m/ g), 'mul(t,n/g) = ', mul(t, n / g), 'm/g = ', m/g, 'n/g = ', n/g)
    if(mul(s,m /g) === mul(t, n / g)){
        return mul(s, m / g);
    } else {
        return -1;
    }
}

module.exports = b;

'use strict'

let q = readline();
    while(q--)
    {
        let s = readline(), sn = "";
        let t = readline(), tn = "";
        let c = false;
        function gcd(a, b){return (b == 0)? a : gcd(b, a % b);}
        let sl = t.length/gcd(s.length, t.length);
        let tl = s.length/gcd(s.length, t.length);
        for(let i = 0; i < sl; i++)sn +=s;
        for(let i = 0; i < tl; i++)tn +=t;
        print(sn == tn ? sn : -1);
    }

"use strict"

let iter = parseInt(readline());

for(iter; iter > 0; iter--){
    let a = readline();
    let b = readline();

    let str1 = b;
    let str2 = a;

    let gcd = greatestCommonDivisor(a.length, b.length)

    let i1 = a.length / gcd;
    let i2 = b.length / gcd;
    for(i1; i1 > 1; i1--){
        str1 += b;
    }
    for(i2; i2 > 1; i2--){
        str2 += a;
    }

    if(str1 === str2){
        print(str1);
    } else {
        print(-1);
    }
}

function greatestCommonDivisor(a, b){
    if(b === 0) return a;
    return greatestCommonDivisor(b, 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++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    var d1 = sL / stringL
    var d2 = tL / stringL
    // console.log(sL % stringL, tL % stringL)
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    var ans = (d1*d2)
    // console.log(string.repeat(d1), s, string.repeat(d2), t)
    // console.log(sL, tL, stringL)
    // console.log(ans, sL % tL, tL % tL)
    ans = ans === 0 ? 1 : ans
    if (string.repeat(d1) === s && string.repeat(d2) === t) {
        if(d1 === 1) return string.repeat(d2)
        if(d2 === 1) return string.repeat(d1)
        if(sL % tL === 0) return s
        if(tL % sL === 0) return t

        return string.repeat(ans)
    }
    return false
}

// '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();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    var d1 = sL / stringL
    var d2 = tL / stringL
    // console.log(sL % stringL, tL % stringL)
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    var ans = (tL*sL/stringL / stringL)
    // console.log(string.repeat(d1), s, string.repeat(d2), t)
    // console.log(sL, tL, stringL)
    // console.log(ans)
    ans = ans === 0 ? 1 : ans
    if (string.repeat(d1) === s && string.repeat(d2) === t) {
        if(d1 === 1) return string.repeat(d2)
        if(d2 === 1) return string.repeat(d1)

        return string.repeat(ans)
    }
    return false
}

// '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();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    var d1 = sL / stringL
    var d2 = tL / stringL
    // console.log(sL % stringL, tL % stringL)
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    var ans = (tL*sL/stringL)
    // console.log(string.repeat(d1), s, string.repeat(d2), t)
    // console.log(ans)
    // console.log(ans)
    ans = ans === 0 ? 1 : ans
    if (string.repeat(d1) === s && string.repeat(d2) === t) {
        if(d1 === 1) return string.repeat(d2)
        if(d2 === 1) return string.repeat(d1)

        return string.repeat(ans)
    }
    return false
}

// '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();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    var d1 = sL / stringL
    var d2 = tL / stringL
    // console.log(sL % stringL, tL % stringL)
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    var ans = (d1*d2/stringL)
    // console.log(string.repeat(d1), s, string.repeat(d2), t)
    // console.log(ans)
    // console.log(ans)
    ans = ans === 0 ? 1 : ans
    if (string.repeat(d1) === s && string.repeat(d2) === t) {
        if(d1 === 1) return string.repeat(d2)
        if(d2 === 1) return string.repeat(d1)

        return string.repeat(ans)
    }
    return false
}

// '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();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    var d1 = sL / stringL
    var d2 = tL / stringL
    // console.log(sL % stringL, tL % stringL)
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    var ans = (d1===1 ?0:d1 + d2===1 ?0:d2) *2
    // console.log(string.repeat(d1),s, string.repeat(d2), t)
    // console.log(ans)
    ans = ans === 0? 1: ans
    if (string.repeat(d1) === s && string.repeat(d2) === t) {

        return string.repeat(ans)
    }
    return false
}

// '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();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    var d1 = sL / stringL
    var d2 = tL / stringL
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    var ans = (d1===1 ?0:d1 + d2===1 ?0:d2) *2
    if (string.repeat(d1) === s && string.repeat(d2) === t) {

        return string.repeat(ans)
    }
    return false
}

// '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();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    if (string.repeat(sL / stringL) === s && string.repeat(tL / stringL) === t) return string.repeat(sL / stringL + tL / stringL)
    return false
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let str1 = readline().trim().split("");
    let str2 = readline().trim().split("");
    let len;
    if (str1.length > str2.length)
      len =
        str1.length % str2.length === 0
          ? str1.length
          : str1.length * str2.length;
    else
      len =
        str2.length % str1.length === 0
          ? str2.length
          : str1.length * str2.length;
    let n1 = [],
      n2 = [];
    for (let i = 0; i < len; i++) n1.push(str1[i % str1.length]);
    for (let i = 0; i < len; i++) n2.push(str2[i % str2.length]);
    let ans = true;
    for (let i = 0; i < len; i++) {
      if (n1[i] !== n2[i]) {
        ans = false;
        break;
      }
    }
    console.log(`${ans === true ? n1.join("") : -1}`);
  }
};
solve();

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

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

function main() {
	let t = +readLine();
	while (t--) {
		const s1 = readLine();
		const s2 = readLine();
		let [small, large] = ['', ''];
		if (s1 < s2) {
			[small, large] = [s1, s2];
		} else {
			[small, large] = [s2, s1];
		}
		const [smallLen, largeLen] = [small.length, large.length];
		if (largeLen % smallLen === 0) {
			if (small.repeat(largeLen / smallLen) === large) console.log(large);
			else console.log(-1);
		} else {
			if (small.repeat(largeLen) === large.repeat(smallLen)) {
				console.log(small.repeat(largeLen));
			} else console.log(-1);
		}
	}
}

'use strict'

let q = readline();
    while(q--)
    {
        let s = readline();
        let t = readline();
        let c = false;
        if(t.length > s.length)
        {
            let temp = s;
            s = t;
            t = temp;
        }
        function gcd(a, b){return (b == 0)? a : gcd(b, a % b);}
        let sl = t.length/gcd(s.length, t.length);
        for(let i = 1; i < sl; i++)s+=s;
        if(s.includes(t))
        {
            c = true;
            let a = s.split(t);
            for(let i = 0; i < a.length; i++)if(a[i].length)c = false;
        }
        print(c? s : -1);
    }

'use strict'

let q = readline();
    while(q--)
    {
        let s = readline();
        let t = readline();
        let c = true;
        if(t.length > s.length)
        {
            let temp = s;
            s = t;
            t = temp;
        }
        function gcd(a, b){return (b == 0)? a : gcd(b, a % b);}
        let sl = t.length/gcd(s.length, t.length);
        for(let i = 1; i < sl; i++)s+=s;
        if(s.includes(t))
        {
            let a = s.split(t);
            for(let i = 0; i < a.length; i++)if(a[i].length)c = false;
        }
        print(c? s : -1);
    }

"use strict"

let iter = parseInt(readline());

for(iter; iter > 0; iter--){
    let a = readline();
    let b = readline();

    if(a.length > b.length){
        let bufer = b;
        b = a;
        a = bufer;
    }

    if(b.indexOf(a) === -1){
        print(-1);
    } else {
        let str = b;
        let i = a.length / greatestCommonDivisor(a.length, b.length);
        for(i; i > 1; i--){
            str += b;
        }

        if(str.slice(-b.length, str.length) === b && str.slice(-a.length, str.length) === a){
            print(str);
        } else {
            print(-1);
        }
    }
}

function greatestCommonDivisor(a, b){
    if(b === 0) return a;
    return greatestCommonDivisor(b, a % b);
}