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

let t = +readline()
while(t--){
    let [n,l,r] = readline().split(' ').map(x=>+x);
    let arr = readline().split(' ').map(x=>+x);
    console.log(`${solve(arr,n,l,r)}`);
}
function solve(nums, n, l, r){
    let result = 0;
    let mid, min, max,sum, left, right;
    nums.sort((a,b)=>a-b);
    for(let i = n-1; i >= 0; i--){
        left = -1;
        right = i;

        while((right - left)>1){
            mid = Math.floor((left+right)/2);
            sum = nums[mid] + nums[i];
            if(sum >= l && sum <= r) right = mid;
            else if(sum < l) left = mid;
            else if(sum > r) right = mid;
        }
        if(right !== i){
            minIdx = right;
            left = -1;
            right = i;
            while((right-left)>1){
                mid = Math.floor((left+right)/2);
                sum = nums[mid] + nums[i];
                if(sum >= l && sum <= r) left = mid;
                else if(sum < l) left = mid;
                else if(sum > r) right = mid;
            }
            maxIdx = left;
            result += maxIdx - minIdx +1;
        }
    }
    return result;
}

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

let t = +readline();

while(t--){
    let [n, l, r] = readline().split(' ').map(x=>+x);
    let arr = readline().split(' ').map(x=>+x);
    console.log(`${solve(arr,n,l,r)}`);
}

function solve(nums, n, l, r){
    let minIdx, maxIdx, sum, mid, left, right;
    let result = 0;
    nums.sort((a, b)=> a-b);

    for(let i = n-1; i >= 0; i--){
        left = -1;
        right = i;
        while((right-left)>1){
            mid = Math.floor((right + left)/2);
            sum = nums[mid] + nums[i];
            if(sum >= l && sum <= r) right = mid;
            else if(sum < l) left = mid;
            else if(sum > r) right = mid;
        }
        if(right !== i){
            minIdx = right;
            left = -1;
            right = i;
            while((right-left)>1){
                mid = Math.floor((right+left)/2);
                sum = nums[mid] + nums[i];
                if(sum >= l && sum <= r) left = mid;
                else if(sum > r) right = mid;
                else  if(sum < l) left = mid;
            }
            maxIdx = left;
            result += maxIdx - minIdx +1;
        }
    }

    return result;
}

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

function main(){
    var nlr, n, l, r, arr;
    var sum, result;
    var i, j, k;

    var numberOfLines = parseInt(readline(), 10);

    for (i = 0; i < numberOfLines; i++) {
        nlr = readNumArray();
        n = nlr[0];
        l = nlr[1];
        r = nlr[2];

        arr = readNumArray();

        arr.sort(function sortF(a, b) {
                if (a < b) {
                    return -1;
                }
                if (a > b) {
                    return 1;
                }
                return 0;
            }
        );

        result = 0;

        for(j = 1; j < arr.length; j +=1){
            var lb = l - arr[j];
            var ub = r - arr[j];

            var lower = lowerbound(arr, lb, -1, j);
            var upper = upperbound(arr, ub, -1, j);

            if(lower !== -1 && upper !== -1){
                result = Math.max(upper - lower + 1, 0) + result;
            }
        }
        print(result);

    }
}

const lowerbound = (arr, x, i, j) => {
    var f = i;
    var l = j;
    var lb = -1;

    while(l - f > 1){
        mid = Math.ceil((l + f) / 2);
        if(arr[mid] >= x){
            lb = mid;
            l = mid
        }else{
            f = mid;
        }

    }
    return lb;
};

const upperbound = (arr, x, i, j) => {
    var f = i;
    var l = j;
    var ub = -1;

    while(l - f > 1){
        mid = Math.ceil((l + f) / 2);
        if(arr[mid] <= x){
            ub = mid;
            f = mid
        }else{
            l = mid;
        }

    }
    return ub;

};

main();

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');

let currentline = 0;
function readline(){
    return input[currentline++];
}

let t = +readline();

while(t--){
    let [n, l, r] = readline().split(' ').map(x => +x);
    let arr = readline().split(' ').map(x => +x);
    console.log(`${solve(arr, n, l, r)}`)
}

function solve(nums, n, l, r){
    let i, j, mid, result=0, temp, ll, rr, lll;
    nums.sort((a,b)=>a-b);
    for(i = n-1; i >= 0; i--){
        rr = i;
        ll = -1;

        while((rr-ll)>1){
            mid = Math.floor((ll+rr)/2);
            temp = nums[mid] + nums[i];
            if(temp >= l && temp <= r) rr = mid;
            else if(temp > r) rr = mid;
            else if(temp < l) ll = mid;
        }
        if(rr !== i){
            lll = rr;
            rr = i;
            ll = -1;
            while((rr-ll)>1){
                mid = Math.floor((ll+rr)/2);
                temp = nums[mid] + nums[i];
                if(temp >= l && temp <= r) ll = mid;
                else if(temp > r) rr = mid;
                else if(temp < l) ll = mid;
            }

            result += ll - lll+1;
        }
    }

    return result;
}

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

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));
// a sample creepy solution
function main () {
	let T = rn();
	while (T--) {
		const [n, l, r] = rna();
		const a = rna();

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

		function countBelow (cutoff) {
			let tot = 0;
			for (let i = 0, j = n-1; i < n-1; i++) {
				while (i < j && a[i] + a[j] > cutoff)
					j--;
				tot += Math.max(0, j - i);
			}
			return tot;
		}

		console.log(countBelow(r) - countBelow(l-1));
	}
}

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

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

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

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

		function lowerBound (l, r, x) {
			while (l < r) {
				mid = l + r >> 1;
				if (a[mid] >= x)
					r = mid;
				else
					l = mid + 1;
			}
			return a[l] >= x ? l : 0;
		}

		function upperBound (l, r, x) {
			while (l < r) {
				mid = l + r + 1 >> 1;
				if (a[mid] <= x)
					l = mid;
				else
					r = mid-1;
			}
			return a[l] <= x ? l : 0;
		}

		let ans = 0;
		for  (let i = 0; i < n-1; i++) {
			const ub = upperBound(i+1, n-1, r - a[i]);
			const lb = lowerBound(i+1, n-1, l - a[i]);
			if (ub && lb)
				ans += ub - lb + 1;
		}

		console.log(ans);
	}
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function gcd(x, y) {
   if (y === 0) {
      return x;
   }
   return gcd(y, x % y);
}

function div(a, b) {
   return Math.floor(a / b);
}

// Индекс первого в отсотрированном arr на промежутке [l, r), который строго больше value
function bins(arr, value, l, r) {
   if (arr[l] > value) {
      return l;
   }
   if (arr[r - 1] <= value) {
      return r;
   }
   while (r - l > 1) {
      var m = ((r + l) >> 1) - ((r + l + 1) & 1);
      if (arr[m] <= value) {
         l = m + 1;
         continue;
      }
      r = m + 1;
   }
   return l;
}

function solve() {
   var nlr = readArray(Number);
   var n = nlr[0];
   var l = nlr[1];
   var r = nlr[2];
   var arr = readArray(Number);
   arr.sort(sortF);
   var ans = 0;
   for (var i = 1; i < n; i++) {
      var li = bins(arr, l - arr[i] - 1, 0, i);
      var ri = bins(arr, r - arr[i], 0, i);
      ans += ri - li;
   }
   write(ans);
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort(function sortF(a, b) {
			   if (a < b) {
				  return -1;
			   }
			   if (a > b) {
				  return 1;
			   }
			   return 0;
			}
		 );

		result = 0;

		for (j = 1; j < n; j++) {
			var ll = l - arr[j];
			var rr = r - arr[j];
			var lb = lowBound(arr, ll, 0, j-1);
			var ub = upperBound(arr, rr, 0, j-1);

			if(lb!=-1 && ub!=-1)
			{
				result = Math.max(ub - lb + 1, 0) + result;
			}

		}

		print(result);
	}
}

function lowBound(arr, x, i, j) {
	var l = i;
	var r = j;
	var lb = -1;

	var m;

	while(l <= r){
		m = Math.ceil((l + r) / 2);
		if(arr[m] >= x) {
			lb = m;
			r = m - 1;
		} else {
			l = m + 1;
		}
	}
	return lb;

}

function upperBound(arr, x, i, j) {
	var l = i;
	var r = j;
	var ans = -1;

	var m;

	while(l <= r){
		m = Math.ceil((l + r) / 2);
		if(arr[m] <= x) {
			ans = m;
			l = m + 1;
		} else {
			r = m - 1;
		}
	}
	return ans;

}

main();

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');

let currentline = 0;
function readline(){
    return input[currentline++];
}

let t = +readline();

while(t--){
    let [n, l, r] = readline().split(' ').map(x => +x);
    let arr = readline().split(' ').map(x => +x);
    console.log(`${solve(arr, n, l, r)}`)
}

function solve(nums, n, l, r){
    let result = 0;
    nums.sort((a,b)=>a-b);
    let end = n-1;
    let start = 0;
    let maxIdx;
    let minIdx;

    while(nums[end] > r && end >= 0) end--;
    for(let i = end; i >= 0; i--){
        let max = r-nums[i];
        let min = nums[i]-l;
        let left = 0;
        let right = i-1
        if(min < 0 && nums[i] < max){
            if(min + nums[i-1] < 0 || nums[i] + nums[i-1]< max)break;
            result++;
            continue;
        };
        // console.log({min},{max},{right})
        if(nums[right] <=  max){
            maxIdx = right;
        }else{
        //look for max
            while(left < right){
                let mid = Math.floor((left+right)/2)
                if(nums[mid] <= max && nums[mid+1] <= max) left = mid+1;
                else right = mid-1
            }
            maxIdx = left;
        }
        left = 0;
        right = end-1
        if(nums[left] >= min){
            minIdx = left;
        }else{
            while(left < right){
                let mid = Math.floor((left+right)/2)
                if(nums[mid] >= min && nums[mid-1] >= min) right = mid-1;
                else left = mid+1;
            }
            minIdx = right;
        }
        // console.log({minIdx},{maxIdx})
        result += maxIdx-minIdx+1;
    }

    return result;
}

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort();

		result = 0;

		for (j = 0; j < n -1; j++) {
			if(arr[j] > r) {
				break;
			}

			for (k = j + 1; k < n; k++){
				sum = arr[j] + arr[k];

				if (l <= sum && sum <= r) {
					result++;
				}
			}
		}
		print(result);
	}
}

main();

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort();

		result = 0;

		for (j = 0; j < n -1; j++) {
			if(arr[j] > r) {
				break;
			}

			for (k = j + 1; k < n; k++){
				sum = arr[j] + arr[k];

				if (sum > r) {
					break;
				} else if (l <= sum && sum <= r) {
					result++;
				}
			}
		}
		print(result);
	}
}

main();

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort();

		result = 0;

		for (j = 0; j < n -1; j++) {
			if(arr[j] >= r) {
				break;
			}

			for (k = j + 1; k < n; k++){
				sum = arr[j] + arr[k];

				if (sum > r) {
					break;
				} else if (l <= sum && sum <= r) {
					result++;
				}
			}
		}
		print(result);
	}
}

main();

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort();

		result = 0;

		for (j = 0; j < n -1; j++) {
			if(arr[j] >= r) {
				break;
			}

			if(arr[j+1] >= r){
				continue;
			}

			for (k = j + 1; k < n; k++){

				sum = arr[j] + arr[k];

				if(l <= sum && sum <= r) {
					result++;
				}
			}
		}
		print(result);
	}
}

main();

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort();

		result = 0;

		for (j = 0; j < n -1; j++) {
			if(arr[j] >= r) {
				break;
			}

			for (k = j + 1; k < n; k++){

				sum = arr[j] + arr[k];
				if(sum > r) {
					break;
				}

				if(l <= sum && sum <= r) {
					result++;
				}
			}
		}
		print(result);
	}
}

main();

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort();

		result = 0;

		for (j = 0; j < n -1; j++) {
			if(arr[j] >= r) {
				break;
			}

			if(arr[j+1] >= r){
				break;
			}

			for (k = j + 1; k < n; k++){

				sum = arr[j] + arr[k];
				if(sum > r) {
					break;
				}

				if(l <= sum && sum <= r) {
					result++;
				}
			}
		}
		print(result);
	}
}

main();


process.stdin.setEncoding('ASCII');
let string = '';
process.stdin.on('data', (data) => string += data);

const main = ( input ) => {
    let n = Number(input[0]);
    let arr = input[1].split(' ').map(Number);

    let freq = {};
    for (let i = 0; i < arr.length; ++i) freq[arr[i]] = i + 1;

    for (let i = 0; i < arr.length; ++i) {
        for (let j = 0; j < arr.length; ++j) {
            if (i == j) continue;

            let val = arr[i] + arr[j];
            if ( freq[val] !== undefined ) {
                console.log(freq[val], i + 1, j + 1);
                return;
            }
        }
    }

    console.log(-1);
}

process.stdin.on('end', () => main(string.trim().split('\n')));

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var ans = "-1";
var indicator = 0, N;
var needBreak = false;
rl.on('line', (input) => {

    if (indicator == 0) {
        N = parseInt(input);
        indicator++;
    }
    else {
        var cont = input.split(' ').map(item => parseInt(item));
        for (let i = 0; i < N; i++) {
            for (let j = 0; j < N; j++) {
                if (j == i)
                    continue;
                for (let k = 0; k < N; k++) {
                    if (k == i || k == j)
                        continue;
                    if (cont[i] == cont[j] + cont[k]) {
                        //console.log("cont[%d]=%d  cont[%d]=%d cont[%d]=%d",i,cont[i],j,cont[j],k,cont[k]);
                        ans = (i + 1).toString() + " " + (j + 1).toString() + " " + (k + 1).toString();
                        needBreak = true;
                        break;
                    }
                }
                if (needBreak)
                    break;
            }
            if (needBreak)
                break;
        }
        console.log(ans);
        rl.close();
    }

});

const readline = require('readline');

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

var ans = "-1", n = -1;

rl.on('line', (input) => {
    if (n == -1)
        n = parseInt(input);
    else {

        let cont = input.split(' ').map(item => parseInt(item));

        for (let i = 0; i < n; i++) {
            for (let j = 0; j < n; j++) {
                if (i == j)
                    continue;
                for (let k = 0; k < n; k++) {
                    if (k == i || k == j)
                        continue;
                    if (cont[i] == cont[j] + cont[k]) {
                        ans = (i + 1) + " " + (j + 1) + " " + (k + 1);
                        break;
                    }

                }
                if (ans != "-1")
                    break;
            }
            if (ans != "-1")
                break;

        }
        console.log(ans);
        rl.close();
    }

});

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

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

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

function main() {
	var n = parseInt(readline());
	var worms = tokenizeIntegers(readline());

	var wormHash = {};
	for (var i = 0; i < n; ++i) {
		wormHash[worms[i]] = i;
	}

	for (var i = 0; i < n; ++i) {
		for (var j = i+1; j < n; ++j) {
			var k = wormHash[worms[i]+worms[j]];
			if (k != undefined) {
				print([k+1, i+1, j+1].join(" "));
				return;
			}
		}
	}

	print(-1);
}

main();

'use strict'

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

let res = (function () {
  for (let i = 0; i < N - 1; i++) {
    for (let j = i + 1; j < N; j++) {
      let k = lll.indexOf(lll[i] + lll[j])
      if (~k) return [i, j, k]
    }
  }
})()

print (res ? ++res[2] + ' ' + ++res[1] + ' ' + ++res[0] : -1)

'use strict'

let N = +readline()
let lll = readline().split(' ').map(v => parseInt(v)).sort((a, b) => a - b)

let res = (function () {
  for (let i = 0; i < N - 1; i++) {
    for (let j = i + 1; j < N; j++) {
      let k = lll.indexOf(lll[i] + lll[j])
      if (~k) return [i, j, k]
    }
  }
})()

print (res ? ++res[2] + ' ' + ++res[1] + ' ' + ++ res[0] : -1)


'use strict'

const problem = (n, f) => {
    let t = new Set(f);
    const g = Array.from({ length: n }, (_, i) => i + 1).filter(i => !t.has(i));
    for (let i = 0, j, prev; i < n; i++) {
        if (f[i]) continue;
        j = g.pop();
        if (j === (i + 1)) {
            if (prev === undefined) { g.push(j); j = g.shift(); }
            else { const t = f[prev]; f[prev] = j; j = t; };
        }

        f[i] = j;
        prev = i;
    }
    return f;
}

print(problem(+readline(), readline().split(' ').map(Number)).join(' '));

"use strict";

let friendsNumber = +readline(); //!
let wishString = readline(); //!
let arrayOfWishNumbers = wishString.split(" ").map(function(item) {
	return +item;
});

let sortedWish = [];
let zeroIndexes = [];
let zeroValues = [];

for (let i = 0; i < arrayOfWishNumbers.length; i++) {
	if (arrayOfWishNumbers[i] === 0) {
		zeroIndexes.push(i);
	}
	sortedWish[i] = 0;
}

for (let i = 0; i < sortedWish.length; i++) {
	if (arrayOfWishNumbers[i] !== 0) {
		sortedWish[arrayOfWishNumbers[i] - 1] = arrayOfWishNumbers[i];
	}
}

for (let i = 0; i < sortedWish.length; i++) {
	if (sortedWish[i] === 0) {
		zeroValues.push(i + 1);
	}
}

let goodSortedZeroValues = [];
//

// zeroValues = zeroValues.reverse();
// if (zeroValues.length % 2 == 1) {
// 	let tempValue = zeroValues[Math.floor(zeroValues.length / 2)];
// 	zeroValues[Math.floor(zeroValues.length / 2)] = zeroValues[Math.floor(zeroValues.length / 2) + 1];
// 	zeroValues[Math.floor(zeroValues.length / 2) + 1] = tempValue;
// }

// let badSortedValues = [];

// for (let i = 0; i < zeroValues.length; i++) {
// 	if (zeroValues[i] = zeroIndexes[i] + 1) {
// 		badSortedValues.push(zeroValues[i]);
// 	}
// }

// for (let i = 0; i < badSortedValues.length; i++) {
// 	for (let j = 0; j < zeroValues.length; j++) {
// 		if (zeroValues[j] === badSortedValues[i]) {
// 			let tempValue = zeroValues[j];
// 			for (let k = 0; k < zeroValues.length; k++) {
// 				if (zeroValues[k] !== 0;)
// 			}
// 		}
// 	}
// }

for (let i = 0; i < zeroValues.length; i++) {
	if (zeroValues[i] === zeroIndexes[i] + 1) {
		for (let j = 0; j < zeroValues.length; j++) {
			let tempValue = zeroValues[i];
			if (zeroValues[i] !== zeroValues[j]) {
				zeroValues[i] = zeroValues[j];
				zeroValues[j] = tempValue;
				break;
			}
		}
	}
}

//
if (zeroValues.length === zeroIndexes.length) {

	for (let i = 0; i < zeroIndexes.length; i++) {
		arrayOfWishNumbers[zeroIndexes[i]] = zeroValues[i];
	}
}

let result = arrayOfWishNumbers.join(" ");

print(result);

'use strict'

const problem = (n, f) => {
    f = f.map(i => i - 1);
    const F = new Set(f);
    const g = [ ...Array(n).keys() ].filter(i => !F.has(i));
    let prev;
    for (let i = 0; i < n; i++) {
        if (f[i] !== -1) continue;
        let j = g.pop();
        if (j === i) {
            if (prev === undefined) { g.push(j); j = g[0]; }
            else { const t = f[prev]; f[prev] = j; j = t };
        }

        f[i] = j;
        prev = i;
    }
    return f.map(i => i + 1).join(' ');
}

print(problem(+readline(), readline().split(' ').map(Number)));

'use strict'

const problem = (n, f) => {
    f = f.map(i => i - 1);
    const g = [ ...Array(n).keys() ].filter(i => !f.includes(i)); // без подарка
    let prev;
    for (let i = 0; i < n; i++) {
        if (f[i] !== -1) continue;
        let j = g.pop();
        if (j === i) {
            if (prev === undefined) { g.push(j); j = g[0]; }
            else { const t = f[prev]; f[prev] = j; j = t };
        }

        f[i] = j;
        prev = i;
    }
    return f.map(i => i + 1);
}

print(problem(+readline(), readline().split(' ').map(Number)));

"use strict";

let friendsNumber = +readline(); //!
let wishString = readline(); //!
let arrayOfWishNumbers = wishString.split(" ").map(function(item) {
	return +item;
});

let sortedWish = [];
let zeroIndexes = [];
let zeroValues = [];

for (let i = 0; i < arrayOfWishNumbers.length; i++) {
	if (arrayOfWishNumbers[i] === 0) {
		zeroIndexes.push(i);
	}
	sortedWish[i] = 0;
}

for (let i = 0; i < sortedWish.length; i++) {
	if (arrayOfWishNumbers[i] !== 0) {
		sortedWish[arrayOfWishNumbers[i] - 1] = arrayOfWishNumbers[i];
	}
}

for (let i = 0; i < sortedWish.length; i++) {
	if (sortedWish[i] === 0) {
		zeroValues.push(i + 1);
	}
}

let goodSortedZeroValues = [];
//

zeroValues = zeroValues.reverse();
if (zeroValues.length % 2 == 1) {
	let tempValue = zeroValues[Math.floor(zeroValues.length / 2)];
	zeroValues[Math.floor(zeroValues.length / 2)] = zeroValues[Math.floor(zeroValues.length / 2) + 1];
	zeroValues[Math.floor(zeroValues.length / 2) + 1] = tempValue;
}

//
if (zeroValues.length === zeroIndexes.length) {

	for (let i = 0; i < zeroIndexes.length; i++) {
		arrayOfWishNumbers[zeroIndexes[i]] = zeroValues[i];
	}
}

let result = arrayOfWishNumbers.join(" ");

print(result);


'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(l, r, data) {
  let count0 = new Array(32).fill(0),
      count1 = new Array(32).fill(0);

  for (let i = 0; i <= r; i++) {
    let cur = data[i];

    for (let j = 0; j < 32; j++) {
      if (cur & 1 << j) count1[j] = count1[j] + 1;else count0[j] = count0[j] + 1;
    }
  }

  let res = 0;

  for (let i = 0; i < 32; i++) {
    if (count0[i] < count1[i]) res |= 1 << i;
  }

  return res;
}

// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\n')

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split('\n');
void function main() {
  let t = Number(inputs[0]),
      __ = 1,
      res = [];

  for (let _ = 0; _ < t; _++) {
    const [l, r] = inputs[__++].split(' ').map(Number);
    let data = inputs[__++].trim().split(' ').map(Number);
    res.push(solve(l, r, data));
  }

  console.log(res.join('\n'));
}();

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

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

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

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

		function cntZeros(a, bit) {
			let cnt = 0;
			for (let i = 0; i <= n; i++) {
				cnt += (a[i] & 1 << bit) == 0;
			}
			return cnt;
		}

		let ans = 0;
		for (let bit = 0; bit <= 16; bit++) {
			if (cntZeros(a, bit) < (n+1)/2) {
				ans += 1 << bit;
			}
		}

		console.log(ans);
	}
}

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

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

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

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

		const b = [];
		for (let i = 0; i <= n; i++) {
			b[i] = i;
		}

		function cntZeros(a, bit) {
			let cnt = 0;
			for (let i = 0; i <= n; i++) {
				cnt += (a[i] & 1 << bit) == 0;
			}
			return cnt;
		}

		let ans = 0;
		for (let bit = 0; bit <= 16; bit++) {
			if (cntZeros(a, bit) != cntZeros(b, bit)) {
				ans += 1 << bit;
			}
		}

		console.log(ans);
	}
}

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

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

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

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

		const b = [];
		for (let i = 0; i <= n; i++) {
			b[i] = i;
		}

		function getZeros(a, pos) {
			let zeros = 0;
			for (let i = 0; i <= n; i++) {
				zeros += (a[i] & 1 << pos) == 0;
			}
			return zeros;
		}

		let ans = 0;
		for (let bit = 0; bit <= 16; bit++) {
			if (getZeros(a, bit) != getZeros(b, bit)) {
				ans += 2**bit;
			}
		}

		console.log(ans);
	}
}

const readline = require('readline')

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

// check(0, 9, 33)

function solve(left, right, arr) {
    const counts = Array(18).fill(0)
    for (let i = 0; i < counts.length; i++) {
        for (let j = 0; j < arr.length; j++) {
            if (arr[j] & (1 << i)) {
                counts[i]++
            }
        }
    }
    const expect = helper(right)
    let ans = 0
    for (let i = 0; i < counts.length; i++) {
        if (counts[i] !== expect[i]) {
            ans |= 1 << i
        }
    }
    // console.log(counts, expect)
    // console.log('-')
    return ans
}
function check(left, right, x) {
    const map = {}
    const arr = []
    for (let i = left; i <= right; i++) {
        const y = i ^ x
        map[y] = (map[y] || []) + 1
        arr.push(y)
    }

    const ans = solve(left, right, arr)
    const map2 = {}
    for (let i = left; i <= right; i++) {
        const y = i ^ ans
        map2[y] = (map2[y] || []) + 1
    }
console.log(ans, map, map2)
    for (let k in map) {
        if (map[k] !== map2[k]) throw 'sb'
    }
}
function helper(x) {
    const log = Math.floor(Math.log2(x))
    const base = Math.pow(2, log)
    // [base, x]
    let counts = Array(18).fill(0)
    if (x > base) {
        counts = helper(x - base)
        counts[log] = x - base + 1
    } else if (x === base) {
        counts[log] = 1
    }
    // [0, base)
    for (let i = 0; i < log; i++) {
        counts[i] += base / 2
    }
// console.log(x, counts)
    return counts
}

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

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

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

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

		const b = [];
		for (let i = 0; i < n; i++) {
			b[i] = i;
		}

		function getZeros(a, pos) {
			let zeros = 0;
			for (let i = 0; i < n; i++) {
				zeros += (a[i] & 1 << pos) == 0;
			}
			return zeros;
		}

		let ans = 0;
		for (let bit = 0; bit <= 16; bit++) {
			if (getZeros(a, bit) != getZeros(b, bit)) {
				ans += 2**bit;
			}
		}

		console.log(ans);
	}
}

const readline = require('readline')

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

function solve(left, right, arr) {
    const counts = Array(18).fill(0)
    for (let i = 0; i < counts.length; i++) {
        for (let j = 0; j < arr.length; j++) {
            if (arr[j] & (1 << i)) {
                counts[i]++
            }
        }
    }
    const expect = helper(right)
    let ans = 0
    for (let i = 0; i < counts.length; i++) {
        if (counts[i] !== expect[i]) {
            ans |= 1 << i
        }
    }
    // console.log(counts, expect)
    // console.log('-')
    return ans
}
function helper(x) {
    const log = Math.floor(Math.log2(x))
    const base = Math.pow(2, log)
    // [base, x]
    let counts = Array(18).fill(0)
    if (x > base) {
        counts = helper(x - base + 1)
        counts[log] = x - base + 1
    } else if (x === base) {
        counts[log] = 1
    }
    // [0, base)
    for (let i = 0; i < log; i++) {
        counts[i] += base / (1 << (i + 1))
    }
// console.log(x, counts)
    return counts
}


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

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

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


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

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) + " ");
	}
}

/******/ (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(' '));


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


(()=>{"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 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);

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


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

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

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


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;