var f = readline().split(" ").map(Number);
var s = f[0];
var n = f[1];
dragons = []

function dragon(x, y){
	this.x = x;
	this.y = y;
}

for(var i = 0; i < n; i++){
	data = readline().split(" ").map(Number);
	dragons.push(new dragon(data[0], data[1]));
}

dragons.sort(function(d1, d2){
	if( (d1.x - d2.x !== 0)){
		return d1.x - d2.x
	}
	else{ //Sort by bonus otherwise
		return d1.y - d1.y;
	}
});

function test(alod, strength){
	mys = strength
	for(var i = 0; i < alod.length; i++){
		if(mys > alod[i].x){
			mys += alod[i].y
		}
		else{
			return false;
		}
	}
	return true;
}

if(test(dragons, s)){
	print("YES")
}
else {
	print("NO")
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function readIntArray() {
  return readline()
    .split(' ')
    .map((num) => parseInt(num));
}

function readFloatArray() {
  return readline()
    .split(' ')
    .map((num) => parseFloat(num));
}

/*=====================START CODING HERE=====================*/

// DONT FUCK WITH THE MAIN FUNCTION !!
function main() {
  let [s, n] = readIntArray();

  let levels = [];
  let flag = false;

  while (n-- > 0) {
    levels.push(readIntArray());
  }

  levels.sort((a, b) => a[0] - b[0]);

  levels.forEach((match) => {
    if (s <= match[0]) {
      flag = false;
    } else {
      s += match[1];
      flag = true;
    }
  });

  console.log(flag ? 'YES' : 'NO');
}

;(function () {

	var s = readline().split(' ');
	var n = +s[1];
	s = +s[0];

	var d = [];
	for (var i = 0; i < n; i++) d.push(readline().split(' ').map(Number));
	d.sort(function(a, b) { return a[0] - b[0]; } );

	for (var i = 0; i < n; i++)
		if (s <= d[i][0]) {
			print('NO');
			return;
		} else s += d[i][1];

	print('YES');

}).call(this);

var s = readline().split(" ");
var level = Number(s[0]), n = Number(s[1]);

var dragons = [];
for(var i=0; i<n; i++) {
    s = readline().split(" ");
    dragons.push({
        level: Number(s[0]),
        exp: Number(s[1])
    });
}

dragons.sort((a,b) => a.level - b.level);

var win = true;
for(var i=0; i<n; i++) {
    if (level > dragons[i].level) {
        level += dragons[i].exp;
    }
    else {
        win = false;
        break;
    }
}
if (win) {
    print('YES')
}
else {
    print('NO')
}

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++];
}
function main() {
  let [heroPower, len] = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  let win = true;
  const enemies = [];

  while (len--) {
    const [enemyPower, point] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    enemies.push([enemyPower, point]);
  }
  enemies.sort((a, b) => a[0] - b[0]);

  len = 0;

  while (len < enemies.length) {
    const [enemyPower, point] = enemies[len];
    if (heroPower <= enemyPower) {
      win = false;
      console.log("NO");
      break;
    }

    if (heroPower > enemyPower) heroPower += point;

    len++;
  }

  if (win) console.log("YES");
}

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

(function() {
  let array = readline().getNumArray(),
    s = array[0],
    n = array[1],
    drakons = [];
  for (let i = 0; i < n; i++) {
    drakons.push(readline().getNumArray());
  }

  drakons.sort((a,b) => a[0] - b[0]);

 for (let i = 0; i < n; i++) {
    if (s > drakons[i][0]) {
      s += drakons[i][1];
    } else {
      write('NO');
      return;
    }
  }
  write('YES');
})();

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

let input = [];

rl.on('line', function(line) {
	input.push(line.split(' ').map((el) => el * 1));
	if (input.length === input[0][1] * 1 + 1) {
		dragons(input);
		rl.close();
	}
});

let dragons = (input) => {
	let array = input;
	let S = array[0][0];
	array.shift();
	array.sort((a, b) => {
		if (a[0] < b[0]) return -1;
		if (a[0] > b[0]) return 1;
		return 0;
	});
	let flag = 1;
	for (let i = 0; i < array.length; i++) {
		if (S > array[i][0]) {
			S += array[i][1];
			continue;
		} else {
			flag = 0;
			break;
		}
	}

	flag === 0 ? console.log('NO') : console.log('YES');
};

var l = readline().split(' ').map(v => parseInt(v, 10));
var n = l[1];
var s = l[0];
var d = [];

for (var  i = 0; i < n; i++) {
    var a = readline().split(' ').map(v => parseInt(v, 10));
    d.push({
        x: a[0],
        y: a[1],
    });
}

d.sort((o1, o2) => {
    return o1.x - o2.x;
});

var good = true;
for (var i = 0; i < n; i++) {
    if (d[i].x >= s) {
        good = false;
        break;
    }
    s += d[i].y;
}

print(good ? 'YES' : 'NO')

const readline = require('readline');

let secondLine = false;

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

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    let dragons = [];

    // Who
    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        const Ds = parseInt(dragon[0]);
        const Db = parseInt(dragon[1]);
        dragons.push([Ds, Db]);
    }

    // Who is first
    dragons = dragons.sort((a, b) => a[0] > b[0] ? 1 : -1);

    // Fight
    for (const dragon of dragons) {
        if (Ks > dragon[0])
            Ks += dragon[1];
        else {
            return console.log("NO")
        }
    }

    console.log("YES")
});

const readline = require('readline');

let secondLine = false;

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

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    let dragons = [];

    // Who
    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        const Ds = parseInt(dragon[0]);
        const Db = parseInt(dragon[1]);
        dragons.push({ strength: Ds, bonus: Db });
    }

    // Who is first
    dragons = dragons.sort((a, b) => a.strength > b.strength ? 1 : -1);

    // Fight
    for (const dragon of dragons) {
        if (Ks > dragon.strength)
            Ks += dragon.bonus;
        else {
            return console.log("NO")
        }
    }

    console.log("YES")
});

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

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

readLine.on('close', () => {
  let [s, n]  = input[0].split(' ').map(x => parseInt(x));
  const dragons = [];

  input.forEach((x, i) => {
    if (i === 0) return;
    const nums = x.split(' ').map(x => parseInt(x));
    dragons.push([
      nums[0], nums[1],
    ]);
  });

  dragons.sort((a, b) => a[0]-b[0]);
  dragons.forEach(d => {
    if (d[0] < s) {
      s += d[1];
    } else {
      console.log('NO'); process.exit();
    }
  });

  console.log('YES');
});

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

const input = [];

function splitAndParseInt(line) {
  return line.split(" ").map((x) => parseInt(x));
}

readLine.on("line", (line) => input.push(line));
readLine.on("close", () => {
  let [s, n] = splitAndParseInt(input[0]);

  const dragons = [];
  for (let i = 1; i <= n; i += 1) {
    const dg = splitAndParseInt(input[i]);
    dragons.push(dg);
  }

  dragons.sort((a, b) => a[0] - b[0]);
  for (const [x, y] of dragons) {
    if (s <= x) {
      console.log("NO");
      return;
    } else {
      s += y;
    }
  }

  console.log("YES");
});

var str = readline().split(" ");
var n = +str[0]; var s = +str[1];
var f = [];

	for (var i=0; i<+s; i++){
 f[i]= readline().split(" ");
	}
	f.sort((x,y)=>x[0]-y[0]);
		for (var i=0; i<+s; i++){
					if (+f[i][0]<n){
					n+=+f[i][1];
				}else break;
		}
	print(i==s?("YES"):"NO");

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

function main() {
	let [s, n] = readLine()
		.split(' ')
		.map(x => parseInt(x));
	let canGoNext = true;
	let dragons = [];

	while (n--) {
		let [x, y] = readLine()
			.split(' ')
			.map(item => parseInt(item));
		dragons.push([x, y]);
	}

	dragons.sort((a, b) => a[0] - b[0]);

	for (let i = 0, l = dragons.length; i < l; ++i) {
		if (s > dragons[i][0]) {
			s = s + dragons[i][1];
		} else {
			canGoNext = false;
			break;
		}
	}

	canGoNext ? console.log('YES') : console.log('NO');
}

let fs = require('fs');

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

for (let i = 0; i < txt.length; i++) {
    let info = txt[i].split(" ");
    let tab = [];
    for (let i1 = i + 1; i1 < i + info[1] * 1 + 1; i1++) {
        tab.push(txt[i1].split(" ").filter(data => data.length > 0).map(data => data * 1));
    }
    i += info[1] * 1;
    doit(info[0] * 1, tab);
}

function doit(n, tab) {
    tab.sort((a, b) => b[1] - a[1]);
    while (tab.length > 0) {
        let test = false;
        for (let i = 0; i < tab.length; i++) {
            if (tab[i][0] < n) {
                test = true;
                n += tab[i][1];
                tab.splice(i, 1);
                break;
            }
        }
        if (!test) {
            console.log("NO");
            return;
        }
    }
    console.log("YES");
}

var input = readline().split(' ');

var s = +input[0];
var n = +input[1];

var Dragon = function(data) {
   this.x = +data[0];
   this.y = +data[1];
};

var dragons = [];
for (var i = 0; i < n; ++i) {
   dragons.push(new Dragon(readline().split(' ')));
}

dragons.sort(function(a, b) {
   return a.x - b.x;
});

for (var i = 0; i < dragons.length; ++i) {
   if (s <= dragons[i].x) {
      write('NO');
      quit();
   }
   s += dragons[i].y;
}

write('YES');

var firstLine = readline().split(" ").map(Number);
var s = firstLine[0];
var n = firstLine[1];
dragons = []

function dragon(x, y){
	this.x = x;
	this.y = y;
}

for(var i = 0; i < n; i++){
	data = readline().split(" ").map(Number);
	dragons.push(new dragon(data[0], data[1]));
}

//Sorted by strengths: always kill the weakest first
dragons.sort(function(d1, d2){
	if( (d1.x - d2.x !== 0)){
		return d1.x - d2.x
	}
	else{ //Sort by bonus otherwise
		return d1.y - d1.y;
	}
});

function test(alod, strength){
	mys = strength
	for(var i = 0; i < alod.length; i++){
		if(mys > alod[i].x){
			mys += alod[i].y
		}
		else{
			return false;
		}
	}
	return true;
}

if(test(dragons, s)){
	print("YES")
}
else{
	print("NO")
}

var f = readline().split(" ").map(Number);
var s = f[0];
var n = f[1];
dragons = []

function dragon(x, y){
	this.x = x;
	this.y = y;
}

for(var i = 0; i < n; i++){
	data = readline().split(" ").map(Number);
	dragons.push(new dragon(data[0], data[1]));
}

dragons.sort(function(d1, d2){
	if( (d1.x - d2.x !== 0)){
		return d1.x - d2.x
	}
	else{ //Sort by bonus otherwise
		return d1.y - d1.y;
	}
});

function test(alod, strength){
	mys = strength
	for(var i = 0; i < alod.length; i++){
		if(mys > alod[i].x){
			mys += alod[i].y
		}
		else{
			return false;
		}
	}
	return true;
}

if(test(dragons, s)){
	print("YES")
}
else{
	print("NO")
}

var str = readline().split(" ");
var n = +str[0]; var s = +str[1];
var f = [];

for (var i=0; i<+s; i++){
    f[i]= readline().split(" ");
}
f.sort((x,y)=>x[0]-y[0]);
for (var i=0; i<+s; i++){
    if (+f[i][0]<n){
		n+=+f[i][1];
	}
	else break;
}
print(i==s?("YES"):"NO");

var s = parseInt(readline().split(' ')[0]);
var dragons = [];
while (true) {
  var input = readline();
  if (!input) break;
  dragons.push(input.split(' ').map(x => parseInt(x)));
}
dragons.sort((a,b) => a[0] - b[0]);
var statement = 'YES';
for (var i = 0; i < dragons.length; i++) {
  if (dragons[i][0] < s) s+= dragons[i][1]
  else {
    statement = 'NO';
    break;
  }
}
print(statement);

"use strict";
var args = readline().split(' ').map(function(x) {return parseInt(x)});
var s = args[0];
var n = args[1];
var i;
var head;
var p;
var dragons = [];

for (i = 0; i < n; i++) {
    args = readline().split(' ').map(function(x) {return parseInt(x)});
    dragons.push({x: args[0], y: args[1]});
}

dragons = dragons.sort(function(a, b) {
    return a.x - b.x;
});

i = 0;
while (i < n) {
    if (s > dragons[i].x) {
        s += dragons[i].y;
        i += 1;
    }
    else {
        print('NO');
        s = -1;
        break;
    }
}
if (s > 0) {
    print('YES');
}

var l=readline().split(' ');
var s=+l[0];
var n=+l[1];
var a=[];
for(var i=0;i<n;i++){
	a.push(readline().split(' ').map(function(v){return+v}));
}
a.sort(function(a,b){return a[0]-b[0]});

for(var i=0;i<n;i++){
	if(a[i][0]<s){
		s+=a[i][1];
	}else{
		break;
	}
}
print(i==n?'YES':'NO')

function sorting(){
	var buf1, buf2;
	for(i = 0; i <= +(n-2); i++){
		for(j = i+1; j <= +(n-1); j++){
			if(+y[i] > +y[j]){
				buf1 = y[i];
				y[i] = y[j];
				y[j] = buf1;
				buf2 = x[i];
				x[i] = x[j];
				x[j] = buf2;
			}
		}
	}
}

var input = readline().split(" "), s = +input[0], n = +input[1], x = [], y = [];
for(i = 0; i < n; i++){
	input = (readline().split(" "));
	x[i] = +input[0];
	y[i] = +input[1];
}

sorting();

for(i = 0; i < x.length; i++){
	if(s > x[i]){
		s += y[i];
		x.splice(i,1);
		y.splice(i,1);
		i = -1;
	}
}

if(x.length == 0){
	write("YES");
}
else{
	write("NO");
}

var s = readline().split(" ");
var s = Number(s[0]), n = Number(s[1]);

var dragons = [];
for(var i=0; i<n; i++) {
    s = readline().split(" ");
    dragons.push({
        level: Number(s[0]),
        exp: Number(s[1])
    });
}

dragons.sort((a,b) => a.level - b.level);

var win = true;
for(var i=0; i<n; i++) {
    if (s > dragons[i].level) {
        s += dragons[i].exp;
    }
    else {
        win = false;
        break;
    }
}
if (win) {
    print('YES')
}
else {
    print('NO')
}

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

(function() {
  let array = readline().getNumArray(),
    s = array[0],
    n = array[1];
  for (let i = 0; i < n; i++) {
    let player = readline().getNumArray();
    if (s > player[0]) {
      s += player[1];
    } else {
      write('NO');
      return;
    }
  }
  write('YES');
})();

var l = readline().split(' ').map(v => parseInt(v, 10));
var n = l[1];
var s = l[0];
var d = [];

for (var  i = 0; i < n; i++) {
    var a = readline().split(' ').map(v => parseInt(v, 10));
    d.push({
        x: a[0],
        y: a[1],
    });
}

d.sort((o1, o2) => {
    return o1.x > o2.x;
});

var good = true;
for (var i = 0; i < n; i++) {
    if (d[i].x >= s) {
        good = false;
        break;
    }
    s += d[i].y;
}

print(good ? 'YES' : 'NO')

var str = readline().split(" ");
var n = +str[0]; var s = +str[1];
var f = [];
	for (var i=0; i<+s; i++){
	 f[i]= readline().split(" ");
	}
	f.sort((x,y)=>x[0]-y[0]);
		for (var i=0; i<+s; i++){
					if (+f[i][0]<n){
					n+=+f[i][1];
				}else break;
		}
	i==n? print("YES"):print("NO");

var str = readline().split(" ");
var n = +str[0]; var s = +str[1];
var f = [];
var c=0;
	for (var i=0; i<+s; i++){
	 f[i]= readline().split(" ");
	}
	f.sort((x,y)=>x[0]-y[0]);
		for (var i=0; i<+s; i++){
					if (+f[c][0]<n){
					n+=+f[c][1];
				}else break;
		}
	i!=n? print("YES"):print("NO");

	var str = readline().split(" ");
	var s = Number(str[0]); var n = Number(str[1]);

	for (var i = 0; i<+n; i++){
		var stroka = readline().split(" ");
		if (s>Number(stroka[0])) s+= Number(stroka[1]);
		else {
		break; print("NO");
		}
		if (i+1==n) 	print("YES");

	}

var str = readline().split(" ");
var n = +str[0]; var s = +str[1];
var f = [];
var c=0;

	for (var i=0; i<+s; i++){
	  f[i]= readline().split(" ");
	}
	f.sort((x,y)=>x-y);
			while (c!=f.length||f.length>1){
					if (+f[c][0]<n){
					n+=+f[c][1];
					f.splice(c, 1);
					c++;
				}else break;
			}
	f.length<1? print("YES"):print("NO");

	var str = readline().split(" ");
	var s = +str[0]; var n = +str[1];

	for (var i = 0; i<n; i++){
		var stroka = readline().split(" ");
		if (s>+stroka[0]) s+= +stroka[1];
		else {
		break; print("NO");
		}

	}
	print("YES");

var str = readline().split(" ");
	var s = Number(str[0]); var n = Number(str[1]);

	for (var i = 0; i<+n; i++){
		var stroka = readline().split(" ");
		if (s>Number(stroka[0])) s+= Number(stroka[1]);
		else {
		print("NO"); break;
		}
		if (i+1==n) 	print("YES");

	}

var str = readline().split(" ");
var n = +str[0]; var s = +str[1];
var f = [];
var c=0;
	for (var i=0; i<+s; i++){
	 f[i]= readline().split(" ");
	}
	f.sort((x,y)=>x[0]-y[0]);
		for (var i=0; i<+s; i++){
					if (+f[c][0]<n){
					n+=+f[c][1];
				}else break;
		}
	i==n? print("YES"):print("NO");

var s = readline().split(' ');
var n = Number(s[1]), power = Number(s[0]);

var k = 0;
for (var i = 0; i<n; i++) {
    var s1 = readline().split(' ');
    var dragon = Number(s1[0]), bonus = Number(s1[1]);

    if (power > dragon) {
        power += bonus;
        k++;
    }

    else {
        k = 0;
    }
}

if (k === 0) {
    print('NO');
}
else {print('YES');}

var s = readline().split(' ');
var n = Number(s[1]), power = Number(s[0]);

var k = 0, m = 0;
for (var i = 0; i<n; i++) {
    var s1 = readline().split(' ');
    var dragon = Number(s1[0]), bonus = Number(s1[1]);

    if (power > dragon) {
        power += bonus;
        k++;
    }

    else {
        m++;
    }
}

if (k < m) {
    print('NO');
}
else {print('YES');}

var s = readline().split(' ');
var n = Number(s[1]), power = Number(s[0]);

var k = 0, m = 0;
for (var i = 0; i<n; i++) {
    var s1 = readline().split(' ');
    var dragon = Number(s1[0]), bonus = Number(s1[1]);

    if (power >= dragon) {
        power += bonus;
        k++;
    }

    else {
        m++;
    }
}

if (k < m) {
    print('NO');
}
else {print('YES');}

var s = readline().split(' ');
var n = Number(s[1]), power = Number(s[0]);

var k = 0;
for (var i = 0; i<n; i++) {
    var s1 = readline().split(' ');
    var dragon = Number(s1[0]), bonus = Number(s1[1]);

    if (power >= dragon) {
        power += bonus;
        k++;
    }

    else {
        k = 0;
    }
}

if (k === 0) {
    print('NO');
}
else {print('YES');}

var input = readline().split(' ');

var s = +input[0];
var n = +input[1];

var Dragon = function(data) {
  this.x = +data[0];
  this.y = +data[1];
};

var dragons = [];
for (var i = 0; i < n; ++i) {
  dragons.push(new Dragon(readline().split(' ')));
}

dragons.sort(function(a, b) {
  return a.x - b.x;
});

for (var i = 0; i < dragons.length; ++i) {
  if (s < dragons[i].x) {
    write('NO');
    quit();
  }
  s += dragons[i].y;
}

write('YES');

var s = parseInt(readline().split(' ')[0]);
var dragons = readline().split(' ').map(x => parseInt(x));
var bonuses = readline();
if (bonuses) bonuses = bonuses.split(' ').map(x => parseInt(x));
var pairs = []
for (var j = 0; j < dragons.length; j++) {
  if (bonuses) pairs.push(dragons[j], bonuses[j]);
  else pairs.push(dragons[j], 0);
}
pairs.sort((a,b) => a[0] - b[0]);
var statement = 'YES';
for (var i = 0; i < dragons.length; i++) {
  if (pairs[i][0] < s) s+=pairs[i][1];
  else {
    statement = 'NO';
    break;
  }
}
print(statement);

var s = parseInt(readline().split(' ')[0]);
var dragons = readline().split(' ').map(x => parseInt(x));
var bonuses = readline();
if (bonuses) bonuses = bonuses.split(' ').map(x => parseInt(x));
var pairs = []
for (var j = 0; j < dragons.length; j++) {
  if (bonuses) pairs.push([dragons[j], bonuses[j]]);
  else pairs.push([dragons[j], 0]);
}
pairs.sort((a,b) => a[0] - b[0]);
var statement = 'YES';
for (var i = 0; i < pairs.length; i++) {
  if (pairs[i][0] < s) s+=pairs[i][1];
  else {
    statement = 'NO';
    break;
  }
}
print(statement);

var s = parseInt(readline().split(' ')[0]);
var dragons = [];
while (true) {
  var input = readline();
  if (!input) break;
  dragons.push(input.split(' ').map(x => parseInt(x)));
}
var statement = 'YES';
for (var i = 0; i < dragons.length; i++) {
  if (dragons[i][0] < s) s+= dragons[i][1]
  else {
    statement = 'NO';
    break;
  }
}
print(statement);

var s = parseInt(readline().split(' ')[0]);
var dragons = readline().split(' ').map(x => parseInt(x));
var bonuses = readline();
if (bonuses) bonuses = bonuses.split(' ').map(x => parseInt(x));
var statement = 'YES';
for (var i = 0; i < dragons.length; i++) {
  if (dragons[i] < s) {
    if (bonuses) s+=bonuses[i];
  } else {
    statement = 'NO';
    break;
  }
}
print(statement);

var args = readline().split(' ').map(parseInt);
var s = args[0];
var n = args[1];
var i = 0;
for (i = 0; i < n; i++) {
    args = readline().split(' ').map(parseInt);
    if (s > args[0]) {
        s += args[1];
    }
    else {
        s = -1;
        break;
    }
}

if (s == -1)
    print('NO');
else
    print('YES');

var args = readline().split(' ').map(function(x) {return parseInt(x)});
var s = args[0];
var n = args[1];
var i = 0;
for (i = 0; i < n; i++) {
    args = readline().split(' ').map(function(x) {return parseInt(x)});
    if (s > args[0]) {
        s += args[1];
    }
    else {
        s = -1;
        break;
    }
}

if (s == -1)
    print('NO');
else
    print('YES');

var l=readline().split(' ');
var s=+l[0];
var n=+l[1];
var a=[];
for(var i=0;i<n;i++){
	a.push(readline().split(' ').map(function(v){return+v}));
}
a.sort(function(a,b){return a[0]-b[1]});

for(var i=0;i<n;i++){
	if(a[i][0]<s){
		s+=a[i][1];
	}else{
		break;
	}
}
print(i==n?'YES':'NO')

var input = readline().split(" "), s = +input[0], n = +input[1];

for(var i = 0; i < n; i++){
	x = readline().split(" ");
	y = +x[1];
	x = +x[0];

	if(s > x){
		s += y;
	}
	else{
		write("NO");
		break;
	}
}

if(i == n){
	write("YES");
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function readIntArray() {
  return readline()
    .split(' ')
    .map((num) => parseInt(num));
}

function readFloatArray() {
  return readline()
    .split(' ')
    .map((num) => parseFloat(num));
}

/*=====================START CODING HERE=====================*/

// DONT FUCK WITH THE MAIN FUNCTION !!
function main() {
  let [s, n] = readIntArray();

  let levels = [];

  while (n-- > 0) {
    levels.push(readIntArray());
  }

  levels.sort((a, b) => {
    if (a[0] === b[0]) {
      return 0;
    } else {
      return a[0] < b[0] ? -1 : 1;
    }
  });

  levels.forEach((match) => {
    let [d, b] = match;

    if (s <= d) {
      console.log('NO');
      return;
    } else {
      s += b;
    }
  });

  console.log('YES');
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function readIntArray() {
  return readline()
    .split(' ')
    .map((num) => parseInt(num));
}

function readFloatArray() {
  return readline()
    .split(' ')
    .map((num) => parseFloat(num));
}

/*=====================START CODING HERE=====================*/

// DONT FUCK WITH THE MAIN FUNCTION !!
function main() {
  let [s, n] = readIntArray();

  let levels = [];

  while (n-- > 0) {
    levels.push(readIntArray());
  }

  levels.sort((a, b) => a[0] - b[0]);

  levels.forEach((match) => {
    let [d, b] = match;

    if (s < d) {
      console.log('NO');
      return;
    } else {
      s += b;
    }
  });

  console.log('YES');
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function readIntArray() {
  return readline()
    .split(' ')
    .map((num) => parseInt(num));
}

function readFloatArray() {
  return readline()
    .split(' ')
    .map((num) => parseFloat(num));
}

/*=====================START CODING HERE=====================*/

// DONT FUCK WITH THE MAIN FUNCTION !!
function main() {
  let [s, n] = readIntArray();

  let levels = [];

  while (n-- > 0) {
    levels.push(readIntArray());
  }

  levels.sort((a, b) => a[0] - b[0]);

  levels.forEach((match) => {
    let [d, b] = match;

    if (s <= d) {
      console.log('NO');
      return;
    } else {
      s += b;
    }
  });

  console.log('YES');
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function readIntArray() {
  return readline()
    .split(' ')
    .map((num) => parseInt(num));
}

function readFloatArray() {
  return readline()
    .split(' ')
    .map((num) => parseFloat(num));
}

/*=====================START CODING HERE=====================*/

// DONT FUCK WITH THE MAIN FUNCTION !!
function main() {
  let [s, n] = readIntArray();

  let levels = [];

  while (n-- > 0) {
    levels.push(readIntArray());
  }

  levels.sort((a, b) => a[0] - b[0]);

  levels.forEach((match) => {
    if (s <= match[0]) {
      console.log('NO');
      return;
    } else {
      s += match[1];
    }
  });

  console.log('YES');
}

const readline = require('readline');

let secondLine = false;

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

let Ks = 0;
let Ds = 0;

// Read Inputs
rl.on('line', inputLine => {
    const inputs = inputLine.split(' ');

    if (!secondLine) {
        Ks = parseInt(inputs[0]);
        secondLine = true;
        return 0
    } else {
        Ds = parseInt(inputs[0]);
        bonus = parseInt(inputs[1]);
        if (Ks > Ds) {
            Ks += bonus;
            return console.log("YES")
        }
        else {
            return console.log("NO")
        }
    }
});

const readline = require('readline');

let secondLine = false;

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

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    let bonus = 0;
    let Ds = 0;

    // Fight and gain some strength
    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        Ds = parseInt(dragon[0]);
        bonus = parseInt(dragon[1]);
        if (Ks >= Ds) {
            Ks += bonus;
        }
    }

    // Can I move on
    if(Ks >= inputs[n].split(' ')[0]) {
        return console.log("YES");
    } else {
        return console.log("NO");
    }

});

const readline = require('readline');

let secondLine = false;

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

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    let bonus = 0;
    let Ds = 0;

    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        Ds = parseInt(dragon[0]);
        bonus = parseInt(dragon[1]);
        if (Ks > Ds) {
            Ks += bonus;
        } else {
            return console.log("NO")
        }
    }

    return console.log("YES");

});

const readline = require('readline');

let secondLine = false;

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

let Ks = 0;
let Ds = 0;
let n = 1;

// Read Inputs
rl.on('line', inputLine => {
    const inputs = inputLine.split(' ');

    if (n > 0) {
        if (!secondLine) {
            Ks = parseInt(inputs[0]);
            n = parseInt(inputs[1]);
            secondLine = true;
            return
        } else {
            Ds = parseInt(inputs[0]);
            bonus = parseInt(inputs[1]);
            n--;
            if (Ks > Ds) {
                Ks += bonus;
                return console.log("YES")
            }
            else {
                return console.log("NO")
            }
        }
    }
});

const readline = require('readline');

let secondLine = false;

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

let Ks = 0;
let Ds = 0;

// Read Inputs
rl.on('line', inputLine => {
    const inputs = inputLine.split(' ');

    if (!secondLine) {
        Ks = parseInt(inputs[0]);
        secondLine = true;
        return
    } else {
        Ds = parseInt(inputs[0]);
        bonus = parseInt(inputs[1]);
        if (Ks > Ds) {
            Ks += bonus;
            return console.log("YES")
        }
        else {
            return console.log("NO")
        }
    }
    return console.log("NO")
});

const readline = require('readline');

let secondLine = false;

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

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    const dragons = [];
    let bonus = 0;
    let Ds = 0;

    // Fight and gain some strength
    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        Ds = parseInt(dragon[0]);
        dragons.push(Ds);
        bonus = parseInt(dragon[1]);
        if (Ks >= Ds) {
            Ks += bonus;
        }
    }

    // Can I move on
    if(Ks >= Math.max(...dragons)) {
        return console.log("YES");
    } else {
        return console.log("NO");
    }

});

const readline = require('readline');

let secondLine = false;

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

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    let bonus = 0;
    let Ds = 0;

    // Fight and gain some strength
    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        Ds = parseInt(dragon[0]);
        bonus = parseInt(dragon[1]);
        if (Ks > Ds) {
            Ks += bonus;
        }
    }

    // Can I move on
    if(Ks > inputs[n].split(' ')[0]) {
        return console.log("YES");
    } else {
        return console.log("NO");
    }

});

const readline = require('readline');

let secondLine = false;

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

let Ks = 0;
let Ds = 0;
let n = 1;

// Read Inputs
rl.on('line', inputLine => {
    const inputs = inputLine.split(' ');

    if (n > 0) {
        if (!secondLine) {
            Ks = parseInt(inputs[0]);
            n = parseInt(inputs[1]);
            secondLine = true;
            n--;
            return
        } else {
            Ds = parseInt(inputs[0]);
            bonus = parseInt(inputs[1]);
            n--;
            if (Ks > Ds) {
                Ks += bonus;
                return console.log("YES")
            }
            else {
                return console.log("NO")
            }
        }
    }
});

const readline = require('readline');

let secondLine = false;

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

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    let bonus = 0;
    let Ds = 0;

    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        Ds = parseInt(dragon[0]);
        bonus = parseInt(dragon[1]);
        if (Ks > Ds) {
            Ks += bonus;
        } else {
            return console.log("NO")
        }
    }

    return console.log("Yes");

});

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

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

readLine.on('close', () => {
  let [s, n]  = input[0].split(' ').map(x => parseInt(x));
  const dragons = [];

  input.forEach((x, i) => {
    if (i === 0) return;
    const nums = x.split(' ').map(x => parseInt(x));
    dragons.push([
      nums[0], nums[1],
    ]);
  });

  dragons.sort((a, b) => a[0]-b[0]);
  dragons.forEach(d => {
    if (d[0] <= s) {
      s += d[1];
    } else {
      console.log('NO'); process.exit();
    }
  });

  console.log('YES');
});

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

function main() {
	let [s, n] = readLine()
		.split(' ')
		.map(x => parseInt(x));
	let canGoNext = true;

	while (n--) {
		let [x, y] = readLine()
			.split(' ')
			.map(item => parseInt(item));

		if (s >= x) {
			s = s + y;
		} else {
			canGoNext = false;
			break;
		}
	}

	canGoNext ? console.log('YES') : console.log('NO');
}

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

function main() {
	let [s, n] = readLine()
		.split(' ')
		.map(x => parseInt(x));
	let canGoNext = true;

	while (n--) {
		let [x, y] = readLine()
			.split(' ')
			.map(item => parseInt(item));

		if (s >= x) {
			s = s - x + y;
		} else {
			canGoNext = false;
			break;
		}
	}

	canGoNext ? console.log('YES') : console.log('NO');
}

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

function main() {
	let [s, n] = readLine()
		.split(' ')
		.map(x => parseInt(x));
	let canGoNext = true;
	let dragons = [];

	while (n--) {
		let [x, y] = readLine()
			.split(' ')
			.map(item => parseInt(item));
		dragons.push([x, y]);
	}

	dragons.sort((a, b) => a[0] - b[0]);

	for (let i = 0, l = dragons.length; i < l; ++i) {
		if (s >= dragons[i][0]) {
			s = s + dragons[i][1];
		} else {
			canGoNext = false;
			break;
		}
	}

	canGoNext ? console.log('YES') : console.log('NO');
}


let i = '';
process.stdin.on('data', (c) => {
  i += c;
});
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = i.split(EOL);
  let count = 2;
  while (count < lines.length) {
    let input = lines[count].split(' ');
    input = input.map(num => parseInt(num, 10));
    equalRectangles(input);
    count += 2;
  }
});

function equalRectangles(rectangles) {
  rectangles = rectangles.sort((a, b) => a - b);
  const targetArea = rectangles[rectangles.length - 1] * rectangles[0];

  let leftIndex = 0;
  let rightIndex = rectangles.length - 1;
  while (leftIndex < rightIndex) {
    if (rectangles[leftIndex] * rectangles[rightIndex] !== targetArea ||
      rectangles[leftIndex + 1] * rectangles[rightIndex - 1] !== targetArea) {
      console.log('NO');
      return;
    }
    if (rectangles[leftIndex] !== rectangles[leftIndex + 1] ||
        rectangles[rightIndex] !== rectangles[rightIndex - 1]) {
      console.log('NO');
      return;
    }
    leftIndex += 2;
    rightIndex -= 2;
  }

  console.log('YES');
}

if (process.env.ANT)
{
    global.print = this.print || function(){console.log([...arguments].join(' '))} || require('lol-io').print
    global.write = this.write || require('lol-io').write
    global.readline = this.readline || require('lol-io').readline
    main();
}
else
{
    const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
    global.print = console.log
    global.write = (...args) => {
        process.stdout.write(args.join(' '));
    }
    const lines = []
    rl.on('line', line =>{
        lines.push(line);
    });
    rl.on('close', main)
    let rli = 0;
    global.readline = ()=>lines[rli++];
}

function main(){

    var q = +readline();

    function fun(n, arr){
        arr.sort((a, b)=>a-b);
        const square = arr[0]*arr[arr.length-1];
        for (let i=0; i<arr.length; i+=2)
        {
            if (arr[i]!=arr[i+1] || arr[arr.length-i-1]!=arr[arr.length-i-2] ||
                arr[i]*arr[arr.length-i-1]!=square)
            {
                return false;
            }
        }
        return true
    }

    while (q--)
    {
        const n = +readline();
        const arr = readline().split(' ').map(n=>+n);
        print(fun(n, arr) ? 'YES' : 'NO');
    }

}

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

    function foo (data, n) {
        data.sort((a, b) => b - a);

        //console.log(JSON.stringify(data));
        let squares = [];

        for (let i = 1; i <= n; i++) {
            let x1 = data.shift();
            let x2 = data.shift();

            //console.log(x1, x2)
            if (x1 !== x2) return false;

            let y1 = data.pop();
            let y2 = data.pop();
            if (y1 !== y2) return false;
            squares.push(x1 * y1);
        }

        //console.log(squares);

        return Math.min(...squares) === Math.max(...squares);
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let data = lines[testCount * 2].split(" ").map(Number);
        let n = lines[testCount * 2 - 1].split(" ").map(Number);

        //console.log(data);
        //console.log(n);
        let result = foo(data, n);
        answer += (result ? "YES" : "NO") +"\n";
        testCount++;
    }
    console.log(answer);
})

'use strict'

let q = parseInt(readline())

while (q --> 0) {

    let n = parseInt(readline())
    n = n * 4

    const freq = {}
    let arr = readline().split(' ').map(function (x) {
        return parseInt(x)
    })

    for (let i in arr) {
        if (freq.hasOwnProperty(arr[i])) {
            freq[arr[i]] ++
        } else {
            freq[arr[i]] = 1
        }
    }

    arr.sort((a, b) => a - b)
    const mx = arr.slice(arr.length - 1)

    const area = arr[0] * mx
    let ok = true

    for (let cur in freq) {
        const other = area / cur
        if (freq[cur] !== freq[other] || freq[cur] % 2 !== 0 || freq[other] % 2 !== 0) {
            ok = false
            break
        }
    }

    print(ok ? 'YES': 'NO')
}

'use strict'

const rectangle = (n, a) => {
    const d = {};
    for (let i = 0; i < 4 * n; i++) {
        d[a[i]] = (d[a[i]] || 0) + 1;
    }
    const l = Object.keys(d).sort((x, y) => x - y);
    const len = l.length;
    const s = l[0] * l[len - 1];
    for (let i = 0; i < len / 2; i++) {
        if (s !== l[i] * l[len - 1 - i]) return 'NO';
        if (d[l[i]] !== d[l[len - 1 - i]]) return 'NO';
        if (d[l[i]] % 2) return 'NO';
    }
    return 'YES';
}

const q = parseInt(readline());
for (let i = 0; i < q; i++) {
    write(rectangle(parseInt(readline()), readline().split(' ').map(Number)) + '\n');
}

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

for(var i=1; i<=t; i++) {
    var n = parseInt(readline(), 10);
    var a = readline().split(' '), area = 0, valid = true;

    for(var j=0; j<4*n; j++) {
        a[j] = parseInt(a[j], 10);
    }

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

    area = a[0] * a[4*n-1];

    for(var j=0; j<2*n; j+=2) {
        if((a[j] * a[4*n-1-j]) === area && a[j] === a[j+1] && a[4*n-1-j] === a[4*n-j-2]) continue;
        else {
            valid = false;
            break;
        }
    }

    print(valid ? 'YES' : 'NO');
}

'use strict'

let q = parseInt(readline())

while (q --> 0) {

    let n = parseInt(readline())
    n = n * 4

    const freq = {}
    let arr = readline().split(' ').map(function (x) {
        return parseInt(x)
    })

    for (let i in arr) {
        if (freq.hasOwnProperty(arr[i])) {
            freq[arr[i]] ++
        } else {
            freq[arr[i]] = 1
        }
    }

    arr.sort((a, b) => a - b)
    const mx = arr.slice(arr.length - 1)

    const area = arr[0] * mx
    let ok = true

    for (let cur in freq) {
        const other = area / cur
        if (freq[cur] % 2 !== 0 || freq[other] % 2 !== 0) {
            ok = false
            break
        }
    }

    print(ok ? 'YES': 'NO')
}

'use strict'

let q = parseInt(readline())

while (q --> 0) {

    let n = parseInt(readline())
    n = n * 4

    const freq = {}
    let arr = readline().split(' ').map(function (x) {
        return parseInt(x)
    })

    for (let i in arr) {
        if (freq.hasOwnProperty(arr[i])) {
            freq[arr[i]] ++
        } else {
            freq[arr[i]] = 1
        }
    }

    arr.sort((a, b) => a - b)
    const mx = arr.slice(arr.length - 1)

    let ok = true
    for (let i = n - 1; i >= 0; --i) {
        if (mx % arr[i] !== 0) {
            ok = false
            break
        }
    }

    const area = arr[0] * mx

    for (let i = 0; i < n && ok; ++i) {
        if (freq[arr[i]] === 0) continue
        const other = area / arr[i]

        if (freq[arr[i]] < 2 || freq[other] < 2) {
            ok = false
        } else {
            freq[arr[i]] -= 2
            freq[other] -= 2
        }
    }

    print(ok ? 'YES': 'NO')
}

'use strict'

const rectangle = (n, a) => {
    const d = {};
    for (let i = 0; i < 4 * n; i++) {
        d[a[i]] = (d[a[i]] || 0) + 1;
    }
    const l = Object.keys(d).sort((x, y) => x - y);
    const len = l.length;
    const s = l[0] * l[len - 1];
    for (let i = 0; i < len / 2; i++) {
        if (s !== l[i] * l[len - 1 - i]) return 'NO';
        if (d[l[i]] !== d[l[len - 1 - i]]) return 'NO';
    }
    return 'YES';
}

const q = parseInt(readline());
for (let i = 0; i < q; i++) {
    write(rectangle(parseInt(readline()), readline().split(' ').map(Number)) + '\n');
}

'use strict'

const rectangle = (n, a) => {
    const d = {};
    for (let i = 0; i < n; i++) {
        d[a[i]] = (d[a[i]] || 0) + 1;
    }
    const l = Object.keys(d).sort((x, y) => x - y);
    const len = l.length;
    const s = l[0] * l[len - 1];
    for (let i = 0; i < len / 2; i++) {
        if (s !== l[i] * l[len - 1 - i]) return 'NO';
        if (d[l[i]] !== d[l[len - 1 - i]]) return 'NO';
    }
    return 'YES';
}

const q = parseInt(readline());
for (let i = 0; i < q; i++) {
    write(rectangle(parseInt(readline()), readline().split(' ').map(Number)) + '\n');
}

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

for(var i=1; i<=t; i++) {
    var n = parseInt(readline(), 10);
    var a = readline().split(' '), area = 0, valid = true;

    for(var j=0; j<4*n; j++) {
        a[j] = parseInt(a[j], 10);
    }

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

    for(var j=0; j<2*n; j+=2) {
        if(j===0) {
            area = a[j] * a[4*n-1-j];
        } else {
            if(a[j] * a[4*n-1-j] == area && a[j] == a[j+1] && a[4*n-1-j] == a[4*n-1-j-1]) continue;
            else {
                valid = false;
                break;
            }
        }
    }

    print(valid ? 'YES' : 'NO');
}

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

    function foo (data) {

        function can1 (data) {
            return data.reduce((agr, value, index, array) => {
                if (!agr) return false;
                if (index === array.length - 1) return agr;
                return value === array[index + 1] - 1 || array[index + 1] === 1;
            }, true);
        }

        function can0 (data) {
            return data.reduceRight((agr, value, index, array) => {
                if (!agr) return false;
                if (index === 0) return agr;
                return value === array[index - 1] - 1 || array[index - 1] === 1;
            }, true);
        }

        return can1(data) || can0(data);
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let data = lines[testCount * 2].split(" ").map(Number);
        //console.log(data);
        let result = foo(data);
        answer += (result ? "YES" : "NO") +"\n";
        testCount++;
    }
    console.log(answer);
})

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

    function foo (data, n) {
        data.sort((a, b) => a < b);

        //console.log(data);
        let squares = [];

        for (let i = 1; i <= n; i++) {
            let x1 = data.shift();
            let x2 = data.shift();
            if (x1 !== x2) return false;

            let y1 = data.pop();
            let y2 = data.pop();
            if (y1 !== y2) return false;
            squares.push(x1 * y1);
        }

        //console.log(squares);

        return Math.min(...squares) === Math.max(...squares);
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let data = lines[testCount * 2].split(" ").map(Number);
        let n = lines[testCount * 2 - 1].split(" ").map(Number);

        //console.log(data);
        //console.log(n);
        let result = foo(data, n);
        answer += (result ? "YES" : "NO") +"\n";
        testCount++;
    }
    console.log(answer);
})

let i = '';
process.stdin.on('data', (c) => {
  i += c;
});
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = i.split(EOL);
  let count = 2;
  while (count < lines.length) {
    let input = lines[count].split(' ');
    input = input.map(num => parseInt(num, 10));
    equalRectangles(input);
    count += 2;
  }
});

function equalRectangles(rectangles) {
  const map = new Map();
  for (const rect of rectangles) {
    if (map.get(rect)) {
      map.set(rect, map.get(rect) + 1);
    } else {
      map.set(rect, 1);
    }
  }

  if (map.size === 1) {
    console.log('YES');
    return;
  }

  const keys = Array.from(map.keys()).sort((a, b) => a - b);
  const targetArea = keys[0] * keys[keys.length - 1];

  let leftIndex = 0;
  let rightIndex = keys.length - 1;

  while (leftIndex < rightIndex) {
    if (keys[leftIndex] * keys[rightIndex] === targetArea &&
        map.get(keys[leftIndex]) === map.get(keys[rightIndex]) &&
        map.get(keys[leftIndex]) % 2 === 0) {
      leftIndex++;
      rightIndex--;
    } else {
      console.log('NO');
      return;
    }
  }

  if (leftIndex === rightIndex) {
    if (map.get(leftIndex) % 4 === 0) {
      console.log('YES');
    } else {
      console.log('NO');
    }
  } else {
    console.log('YES');
  }
}

let i = '';
process.stdin.on('data', (c) => {
  i += c;
});
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = i.split(EOL);
  let count = 2;
  while (count < lines.length) {
    let input = lines[count].split(' ');
    input = input.map(num => parseInt(num, 10));
    equalRectangles(input);
    count += 2;
  }
});

function equalRectangles(rectangles) {
  const map = new Map();
  for (const rect of rectangles) {
    if (map.get(rect)) {
      map.set(rect, map.get(rect) + 1);
    } else {
      map.set(rect, 1);
    }
  }

  if (map.size === 1) {
    console.log('YES');
    return;
  }

  const keys = Array.from(map.keys()).sort((a, b) => a - b);
  const targetArea = keys[0] * keys[keys.length - 1];

  let leftIndex = 0;
  let rightIndex = keys.length - 1;

  while (leftIndex <= rightIndex) {
    if (leftIndex === rightIndex) {
      if (map.get(leftIndex) % 4 === 0) {
        console.log('YES');
        return;
      } else {
        console.log('NO');
        return;
      }
    } else {
      if (keys[leftIndex] * keys[rightIndex] === targetArea &&
          map.get(keys[leftIndex]) === map.get(keys[rightIndex])) {
        leftIndex++;
        rightIndex--;
      } else {
        console.log('NO');
        return;
      }
    }
  }
  console.log('YES');
}

let i = '';
process.stdin.on('data', (c) => {
  i += c;
});
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = i.split(EOL);
  let count = 2;
  while (count < lines.length) {
    let input = lines[count].split(' ');
    input = input.map(num => parseInt(num, 10));
    equalRectangles(input);
    count += 2;
  }
});

function equalRectangles(rectangles) {
  const map = new Map();
  for (const rect of rectangles) {
    if (map.get(rect)) {
      map.set(rect, map.get(rect) + 1);
    } else {
      map.set(rect, 1);
    }
  }

  if (map.size === 1) {
    console.log('YES');
    return;
  }

  const keys = Array.from(map.keys()).sort((a, b) => a - b);
  const targetArea = keys[0] * keys[keys.length - 1];

  let leftIndex = 0;
  let rightIndex = keys.length - 1;

  while (leftIndex < rightIndex) {
    if (leftIndex === rightIndex) {
      if (map.get(leftIndex) % 4 === 0) {
        console.log('YES');
        return;
      } else {
        console.log('NO');
        return;
      }
    } else {
      if (keys[leftIndex] * keys[rightIndex] === targetArea &&
          map.get(keys[leftIndex]) === map.get(keys[rightIndex])) {
        leftIndex++;
        rightIndex--;
      } else {
        console.log('NO');
        return;
      }
    }
  }
  console.log('YES');
}

let i = '';
process.stdin.on('data', (c) => {
  i += c;
});
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = i.split(EOL);
  let count = 2;
  while (count < lines.length) {
    let input = lines[count].split(' ');
    input = input.map(num => parseInt(num, 10));
    equalRectangles(input);
    count += 2;
  }
});

function equalRectangles(rectangles) {
  rectangles = rectangles.sort((a, b) => a - b);
  const targetArea = rectangles[rectangles.length - 1] * rectangles[0];

  let leftIndex = 0;
  let rightIndex = rectangles.length - 1;
  while (leftIndex < rightIndex) {
    if (rectangles[leftIndex++] * rectangles[rightIndex--] !== targetArea ||
      rectangles[leftIndex++] * rectangles[rightIndex--] !== targetArea) {
      console.log('NO');
      return;
    }
  }

  console.log('YES');
}


const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
    // (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim()
            .split(' ')
            .map(Number)
        const edges = lines.slice(l, l + m)
            .map(str => str.trim()
                .split(' ')
                .map(Number))
        l += m
        l++
        const vs = lines[l++].trim()
            .split(' ')
            .map(Number)
        l++
        const indexes = lines[l++].trim()
            .split(' ')
            .map(Number)
        output[i] = solve(n, edges, vs, indexes)
    }
    console.log(output.join('\n'))
    // })()
})
class Queue {
    constructor() {
        this.map = {}
        this.first = 0
        this.last = -1
    }
    push(...args) {
        let i = 0
        if (!this.length) {
            this.first = this.last = 0
            this.map[this.first] = args[i++]
        }
        for (; i < args.length; i++) {
            this.map[++this.last] = args[i]
        }
    }
    unshift(...args) {
        let i = 0
        if (!this.length) {
            this.first = this.last = 0
            this.map[this.first] = args[i++]
        }
        for (; i < args.length; i++) {
            this.map[--this.first] = args[i]
        }
    }
    pop() {
        const r = this.map[this.last]
        delete this.map[this.last]
        this.last--
        return r
    }
    shift() {
        const r = this.map[this.first]
        delete this.map[this.first]
        this.first++
        return r
    }
    get length() {
        if (this.first > this.last) return 0
        return this.last - this.first + 1
    }
    getLast() {
        return this.map[this.last]
    }
    forEach(fn) {
        for (let i = this.first; i <= this.last; i++) {
            fn(this.map[i], i - this.first)
        }
    }
}

function solve(n, edges, vs, indexes) {
    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })
    const ms = {} // v -> mask
    indexes.forEach((idx, i) => {
        idx--
        const v = vs[idx]
        ms[v] = (ms[v] || 0) | (1 << i)
    })
    const count = Array(64)
    for (let h = 0; h < 64; h++) {
        count[h] = 0
        for (let j = 0; j < 6; j++) {
            if (h & (1 << j)) count[h]++
        }
    }
// console.log(car)
    //
    const dp = Array(n + 1)
    bfs(1)
    // console.log(ms)
    // console.log(dp)
    //
    // let prev = Array(n + 1).fill(0)
    // const rm = ms[1] || 0
    // for (let h = 0; h < 64; h++) {
    // prev[h] = (h & rm) === h ? 1 : 0
    // }
    let prev = Array(64).fill(0)
    prev[0] = 1
    for (let i = 0; i < vs.length; i++) {
        const u = vs[i]
    // for (let u = 1; u <= n; u++) {
        const mask = ms[u] || 0
        if (indexes.indexOf(i + 1) >= 0) continue // no car
        const ans = prev.slice()
        for (let x = 0; x < 64; x++) {
            if (!dp[u][x]) continue
            for (let y = 0; y < 64; y++) {
                ans[x | y] |= prev[y]
            }
        }
        prev = ans
        // console.log(u, prev)
    }
    let res = 0
    for (let h = 0; h < 64; h++) {
        if (prev[h]) {
            res = Math.max(res, count[h])
        }
        // res = Math.max(res, prev[h])
    }
    return indexes.length - res

    function bfs(r) {
        let q = new Queue()
        q.push(r)
        const visited = Array(n + 1)
            .fill(Infinity) // for small n
        dp[r] = dp[r] || Array(64)
            .fill(0)
        visited[r] = 0
        let d = 1
        while (q.length) {
            const nq = new Queue()
            // eslint-disable-next-line no-loop-func
            q.forEach(u => {
                // if (visited[u]) return
                // dp[u] = Array(64)
                ;(adj[u] || []).forEach(v => {
                    if (visited[v] < d) return

                    const mask = (ms[v] || 0)
                    dp[v] = dp[v] || Array(64).fill(0)
                    for (let h = 0; h < dp[v].length; h++) {
                        if ((h & mask) === h) {
                            dp[v][h] = 1
                        }
                        dp[v][h] |= dp[u][h]
                        dp[v][h | mask] |= dp[u][h]
                    }
                    // if (v === 4) {
                    // console.log(dp[u], dp[v])
                    // }

                    if (visited[v] > d) {
                        nq.push(v)
                    }
                    visited[v] = d
                })
            })
            q = nq
            d++
        }
        // console.log(visited)
    }
}

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        m = rn();
  const h = new Array(n).fill(-1),
        te = [],
        ne = [];
  const add = (i, j) => (te.push(j), ne.push(h[i]), h[i] = ne.length - 1);
  for (let i = 0; i < m; i++) {
    const [u, v] = rns(2);
    add(u - 1, v - 1);
    add(v - 1, u - 1);
  }
  const FOR = (u, f) => {
    for (let i = h[u]; ~i; i = ne[i]) {
      const v = te[i];
      f(v);
    }
  };
  const f = rn(),
        a = rns(f).map(num => num - 1),
        map = new Map();
  for (let i = 0; i < f; i++) {
    if (!map.has(a[i])) map.set(a[i], new Set());
    map.get(a[i]).add(i);
  }
  const k = rn(),
        b = rns(k).map(num => num - 1);
        new Set(b.map(i => a[i]));
        const set1 = new Set(b),
        ff = new Array(n).fill(0);
  for (let i = 0; i < k; i++) {
    ff[a[b[i]]] |= 1 << i;
  }
  const states = Array.from({
    length: n
  }, () => new Set());
  {
    const dist = new Array(n).fill(Infinity);
    const queue = [0];
    dist[0] = 0;
    states[0].add(0);
    for (let u of queue) {
      FOR(u, v => {
        if (dist[v] >= dist[u] + 1) {
          for (let state of states[u]) {
            states[v].add(state | ff[v]);
          }
        }
        if (dist[v] <= dist[u] + 1) return;
        dist[v] = dist[u] + 1;
        add(u, v);
        queue.push(v);
      });
    }
  }
  const dp = Array.from({
    length: f
  }, () => new Set());
  let pre = -1;
  {
    for (let i = 0; i < f; i++) {
      if (set1.has(i)) continue;
      for (let state of states[a[i]]) {
        dp[i].add(state);
        if (pre !== -1) {
          for (let p of dp[pre]) {
            dp[i].add(p | state);
          }
        }
      }
      pre = i;
    }
  }
  let res = k;
  {
    const cnt = new Array(1 << k).fill(0);
    for (let i = 0; i < 1 << k; i++) {
      for (let j = 0; j < k; j++) if (i & 1 << j) cnt[i]++;
    }
    for (let j of (_dp$pre = dp[pre]) !== null && _dp$pre !== void 0 ? _dp$pre : []) {
      var _dp$pre;
      res = Math.min(res, k - cnt[j]);
    }
  }
  return res;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8')
.split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
    // (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim()
            .split(' ')
            .map(Number)
        const edges = lines.slice(l, l + m)
            .map(str => str.trim()
                .split(' ')
                .map(Number))
        l += m
        l++
        const vs = lines[l++].trim()
            .split(' ')
            .map(Number)
        l++
        const indexes = lines[l++].trim()
            .split(' ')
            .map(Number)
        output[i] = solve(n, edges, vs, indexes)
    }
    console.log(output.join('\n'))
    // })()
})
class Queue {
    constructor() {
        this.map = {}
        this.first = 0
        this.last = -1
    }
    push(...args) {
        let i = 0
        if (!this.length) {
            this.first = this.last = 0
            this.map[this.first] = args[i++]
        }
        for (; i < args.length; i++) {
            this.map[++this.last] = args[i]
        }
    }
    unshift(...args) {
        let i = 0
        if (!this.length) {
            this.first = this.last = 0
            this.map[this.first] = args[i++]
        }
        for (; i < args.length; i++) {
            this.map[--this.first] = args[i]
        }
    }
    pop() {
        const r = this.map[this.last]
        delete this.map[this.last]
        this.last--
        return r
    }
    shift() {
        const r = this.map[this.first]
        delete this.map[this.first]
        this.first++
        return r
    }
    get length() {
        if (this.first > this.last) return 0
        return this.last - this.first + 1
    }
    getLast() {
        return this.map[this.last]
    }
    forEach(fn) {
        for (let i = this.first; i <= this.last; i++) {
            fn(this.map[i], i - this.first)
        }
    }
}

function solve(n, edges, vs, indexes) {
    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })
    const car = vs.reduce((o, x, i) => {
        if (indexes.indexOf(i + 1) < 0) {
            o[x] = 1
        }
        return o
    }, {}) // v -> has car
    const ms = {} // v -> mask
    indexes.forEach((idx, i) => {
        idx--
        const v = vs[idx]
        ms[v] = (ms[v] || 0) | (1 << i)
    })
    const count = Array(64)
    for (let h = 0; h < 64; h++) {
        count[h] = 0
        for (let j = 0; j < 6; j++) {
            if (h & (1 << j)) count[h]++
        }
    }
    //
    const dp = Array(n + 1)
    bfs(1)
    // console.log(ms)
    // console.log(dp)
    //
    // let prev = Array(n + 1).fill(0)
    // const rm = ms[1] || 0
    // for (let h = 0; h < 64; h++) {
    // prev[h] = (h & rm) === h ? 1 : 0
    // }
    let prev = Array(64).fill(0)
    prev[0] = 1
    for (let i = 0; i < vs.length; i++) {
        const u = vs[i]
    // for (let u = 1; u <= n; u++) {
        const mask = ms[u] || 0
        if (!car[u]) continue
        const ans = prev.slice()
        for (let x = 0; x < 64; x++) {
            if (!dp[u][x]) continue
            for (let y = 0; y < 64; y++) {
                ans[x | y] |= prev[y]
            }
        }
        prev = ans
    }
        // console.log(prev)
    let res = 0
    for (let h = 0; h < 64; h++) {
        if (prev[h]) {
            res = Math.max(res, count[h])
        }
        // res = Math.max(res, prev[h])
    }
    return indexes.length - res

    function bfs(r) {
        let q = new Queue()
        q.push(r)
        const visited = Array(n + 1)
            .fill(Infinity) // for small n
        dp[r] = dp[r] || Array(64)
            .fill(0)
        visited[r] = 0
        let d = 1
        while (q.length) {
            const nq = new Queue()
            // eslint-disable-next-line no-loop-func
            q.forEach(u => {
                // if (visited[u]) return
                // dp[u] = Array(64)
                ;(adj[u] || []).forEach(v => {
                    if (visited[v] < d) return

                    const mask = (ms[v] || 0)
                    dp[v] = dp[v] || Array(64).fill(0)
                    for (let h = 0; h < dp[v].length; h++) {
                        if ((h & mask) === h) {
                            dp[v][h] = 1
                        }
                        dp[v][h] |= dp[u][h]
                        dp[v][h | mask] |= dp[u][h]
                    }
                    // if (v === 4) {
                    // console.log(dp[u], dp[v])
                    // }

                    if (visited[v] > d) {
                        nq.push(v)
                    }
                    visited[v] = d
                })
            })
            q = nq
            d++
        }
        // console.log(visited)
    }
}


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

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

var T = readline();
// var inf = 10000000000;
for(var qe=1;qe<=T;qe++) {
  var n = readline()//.split(' ').map((x) => parseInt(x));
  var a = readline().split(' ').map((x) => parseInt(x));
  var ans = 0;
  var cnt = 0, cntZ = 0;
  for(var i=0;i<n;i++) {
    if(a[i] == 0) cnt++;
  }
  var i=0;
  while(i<n && a[i]==0) {
    i++;
    cntZ++;
  }
  var i=n-1;
  while(i>=0 && a[i] == 0) {
    i--;
    cntZ++;
  }
  if(cntZ < cnt) ans = 2;
  if(cntZ == cnt) {
    if(cnt == n) ans = 0;
    else ans = 1;
  }

  console.log(ans);
}

'use strict';

function solve(n, a) {
  let res = 0;
  for (let i = 0, j = 0; i < n; i = ++j) {
    if (a[i] === 0) continue;
    while (j + 1 < n && a[j + 1] !== 0) j++;
    res++;
  }
  return Math.min(res, 2);
}

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

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

'use strict';

function solve(n, a) {
  let res = 0;
  for (let i = 0, j = 0; i < n; i = ++j) {
    if (a[i] === 0) continue;
    while (j + 1 < n && a[j + 1] !== 0) j++;
    res++;
  }
  return res;
}

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

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

'use strict';

function solve(n, a) {
  let res = 0;
  for (let i = 0; i < n; i++) {
    var _a;
    if (a[i] === 0) continue;
    if (((_a = a[i - 1]) !== null && _a !== void 0 ? _a : 0) === 0) res++;
  }
  return res;
}

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

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


var g = (readline()).split(" ");

var x = Number(g[0]);

var y = Number(g[1]);

var flag = false;

var k = "";

var loop_b = false;

var mat = [];
for(i=0;i<x;i++){
     k = readline().split("");

     mat.push(k);
}

k = mat;

var should_be_plus = [];

for(i=0;i<x;i++){
    should_be_plus[i] = [];
    for(b=0;b<y;b++){
        should_be_plus[i][b] = false;
    }
}

for(i=1;i < x-1; i++){
    for(b=1;b<y-1;b++){
        if(k[i][b] == "*" && k[i][b+1] == "*" && k[i][b-1] == "*" && k[i-1][b] == "*" && k[i+1][b] == "*"){

            flag = true;

            var leftend = b, rightend = b, upend = i, downend = i;

			while(upend >= 0 && k[upend][b] == "*"){
			    if(!Array.isArray(should_be_plus[upend]))
			        should_be_plus[upend] = [];

			    should_be_plus[upend--][b] = true;
			}
			while(downend < x && k[downend][b] == "*"){
			     if(!Array.isArray(should_be_plus[downend]))
			        should_be_plus[downend] = [];

			     should_be_plus[downend++][b] = true;

			}
			while(leftend >= 0 && k[i][leftend] == "*"){
			    if(!Array.isArray(should_be_plus[i]))
			        should_be_plus[i] = [];

			    should_be_plus[i][leftend--] = true;

			}
			while(rightend < y && k[i][rightend] == "*"){
			    if(!Array.isArray(should_be_plus[i]))
			        should_be_plus[i] = [];

			    should_be_plus[i][rightend++] = true;

			}

            loop_b = true;
            break;
        }
    }
    if(loop_b)
        break;
}

loop_b = false;

if(flag){
    for(i=0;i<x;i++){
        for(b=0;b < y;b++){
			if(typeof should_be_plus[i][b] != "undefined" && should_be_plus[i][b] !=
			(k[i][b] == '*')){
                flag = false;
                loop_b = true;
			}
        }
        if(loop_b)
            break;
    }
}

if(flag)
    print("YES");
else
    print("NO");

"use strict";

var input = readline().split(' ').map(value => +value);
var h = input[0];
var w = input[1];
var S = [Array(1000).join('.')];

for (let i = 1; i <= h; ++i) {
    let s = '.' + readline() + '.';
    S[i] = s;
}
S.push(Array(1000).join('.'));

var di = [-1, 0, 1, 0];
var dj = [0, 1, 0, -1];
var isCenter = function(i, j) {
    for (let k = 0; k < 4; ++k) {
        if (S[i + di[k]][j + dj[k]] !== '*') {
            return false;
        }
    }
    return true;
};

var fC = 0;
var cI = -1;
var cJ = -1;
for (let i = 1; i <= h; ++i) {
    for (let j = 1; j <= w; ++j) {
        if (S[i][j] === '*') {
            ++fC;
            if (cI === -1 && cJ === -1 && isCenter(i, j)) {
                cI = i; cJ = j;
            }
        }
    }
}

var dfs = function(cI, cJ) {
    var result = 1;

    for (let k = 0; k < 4; ++k) {
        var step = 1;
        while (S[cI + di[k]*step][cJ + dj[k]*step] === '*') {
            ++step;
            ++result;
        }
    }

    return result;
};

write(cI !== -1 && cJ !== -1 && dfs(cI, cJ) === fC ? 'YES' : 'NO');

const fs = require('fs');
const text = fs.readFileSync(0, 'utf8');
const lines = text.split('\n');
const [x, y] = lines[0].trim().split(' ').map(a => parseInt(a, 10));
let sum = 0;
const pic = lines.slice(1, x + 1).map(x => {
    const result = Array.from(x.trim()).map(y => y === '.' ? 0 : 1);
    sum += result.filter(i => i === 1).length;
    return result;
});

// x
const getTop = () => {
    for (let i = 0; i < x; i++) {
        for (let j = 0; j < y; j++) {
            if (pic[i][j]) {
                return [i, j];
            }
        }
    }

    return [-1, -1];
};
const [topX1, topY] = getTop();
if (topX1 === -1) {
    console.log('NO');
    return;
}
let topX2;
for (let i = topX1; i < x; i++) {
    if (pic[i][topY]) {
        topX2 = i;
    } else {
        break;
    }
}
// y
const getLeft = () => {
    for (let j = 0; j < y; j++) {
        for (let i = 0; i < x; i++) {
            if (pic[i][j]) {
                return [i, j];
            }
        }
    }

    return [-1, -1];
};
const [leftX, leftY1] = getLeft();
if (topX1 === -1) {
    console.log('NO');
    return;
}
let leftY2;
for (let i = leftY1; i < y; i++) {
    if (pic[leftX][i]) {
        leftY2 = i;
    } else {
        break;
    }
}

if (leftY2 - leftY1 + topX2 - topX1 + 1 === sum && topY > leftY1 && topY < leftY2 && leftX > topX1 && leftX < topX2) {
    console.log('YES');
} else {
    console.log('NO');
}

const readline = require('readline');

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

var n = 0, m = 0, cnt = 0, s = [];

var solve = function () {
    var vis = []
    for (var i = 0; i < n; i ++) { var tmp = []; for (var j = 0; j < m; j ++) tmp.push(false); vis.push(tmp); }
    var cc = 0, sx, sy;
    for (var i = 1; i+1 < n; i ++) {
        for (var j = 1; j+1 < m; j ++) {
            if (s[i][j] == '*' && s[i][j+1] == '*' && s[i][j-1] == '*' && s[i+1][j] == '*' && s[i-1][j] == '*') {
                cc ++;
                sx = i; sy = j;
            }
        }
    }
    // console.log(`cc == ${cc}`);
    if (cc != 1) return "NO";
    for (var j = sy; j >= 0; j --) if (s[sx][j] == '*') vis[sx][j] = true; else break;
    for (var j = sy; j < m; j ++) if (s[sx][j] == '*') vis[sx][j] = true; else break;
    for (var i = sx; i >= 0; i --) if (s[i][sy] == '*') vis[i][sy] = true; else break;
    for (var i = sx; i < n; i ++) if (s[i][sy] == '*') vis[i][sy] = true; else break;
    for (var i = 0; i < n; i ++) {
        for (var j = 0; j < m; j ++) {
            if (s[i][j] == '*' && !vis[i][j]) return "NO";
        }
    }
    return "YES";
}

rl.on("line", (line) => {
    if (n == 0) {
        var tmp = line.split(' ');
        n = parseInt(tmp[0]);
        m = parseInt(tmp[1]);
    }
    else {
        cnt ++;
        s.push(line);
        if (cnt >= n) {
            console.log( solve() );
            rl.close();
        }
    }
});

(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    };

    var line = read.arrNumber(' ');
    var n = line[0];
    var m = line[1];
    var arr = [];

    for(var i = 0; i < n; i++)
        arr[i] = read.arr();

    var checked = false;
    for(var i = 1; i < n - 1; i++) {
        for(var j = 1; j < m - 1; j++) {
            if(
                !checked
                && arr[i][j] === '*'
                && arr[i][j + 1] === '*'
                && arr[i][j - 1] === '*'
                && arr[i + 1][j] === '*'
                && arr[i - 1][j] === '*'
            ) {
                checked = true;
                arr[i][j] = '.';

                var t = j + 1;
                while(arr[i][t] === '*') {
                    arr[i][t] = '.';
                    t++;
                }

                t = j - 1;
                while(arr[i][t] === '*') {
                    arr[i][t] = '.';
                    t--;
                }

                t = i + 1;
                while(arr[t][j] === '*') {
                    arr[t][j] = '.';
                    if(t < n - 1)
                        t++;
                }

                t = i - 1;
                while(arr[t][j] === '*') {
                    arr[t][j] = '.';
                    if(t > 0)
                        t--;

                }
                break;
            }
        }
        if(checked) {
            break;
        }
    }

    for(var i = 0; i < n; i++) {
        if(arr[i].indexOf('*') !== -1 || !checked) {
            print('NO');
            return;
        }
    }

    print('YES');
}());

(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    };

    var line = read.arrNumber(' ');
    var n = line[0];
    var m = line[1];
    var arr = [];

    for(var i = 0; i < n; i++)
        arr[i] = read.arr();

    var checked = false;
    for(var i = 1; i < n - 1; i++) {
        for(var j = 1; j < m - 1; j++) {
            if(
                !checked
                && arr[i][j] === '*'
                && arr[i][j + 1] === '*'
                && arr[i][j - 1] === '*'
                && arr[i + 1][j] === '*'
                && arr[i - 1][j] === '*'
            ) {
                checked = true;
                arr[i][j] = '.';

                var t = j + 1;
                while(arr[i][t] === '*') {
                    arr[i][t] = '.';
                    t++;
                }

                t = j - 1;
                while(arr[i][t] === '*') {
                    arr[i][t] = '.';
                    t--;
                }

                t = i + 1;
                while(arr[t][j] === '*') {
                    arr[t][j] = '.';
                    if(t < n - 1)
                        t++;
                }

                t = i - 1;
                while(arr[t][j] === '*') {
                    arr[t][j] = '.';
                    if(t > 0)
                        t--;

                }
                break;
            }
        }
        if(checked) {
            break;
        }
    }

    for(var i = 0; i < n; i++) {
        if(arr[i].indexOf('*') !== -1) {
            print('NO');
            return;
        }
    }

    print('YES');
}());

var g = (readline()).split(" ");

var x = Number(g[0]);

var y = Number(g[1]);

var flag = false;

var row_index = 0;
var col_index = 0;
var k = "";

var loop_b = false;

var mat = [];
for(i=0;i<x;i++){
     k = readline().split("");

     mat.push(k);
}

k = mat;

for(i=1;i < x-1; i++){
    for(b=1;b<y-1;b++){
        if(k[i][b] == "*" && k[i][b+1] == "*" && k[i][b-1] == "*" && k[i-1][b] == "*" && k[i+1][b] == "*"){

            flag = true;
            row_index = i;
            col_index = b;

            loop_b = true;
            break;
        }
    }
    if(loop_b)
        break;
}

loop_b = false;

for(i=0;i<x;i++){
    for(b=0;b < y;b++){
        if(k[i][b] == "*" && (b != col_index && i != row_index)){

            flag = false;

            loop_b = true;
            break;
        }
    }
    if(loop_b)
        break;
}

if(flag)
    print("YES");
else
    print("NO");

var g = (readline()).split(" ");

var x = Number(g[0]);

var y = Number(g[1]);

var flag = false;

var row_index = 0;
var col_index = 0;
var k = "";

var loop_b = false;

var mat = [];
for(i=0;i<x;i++){
     k = readline().split("");

     mat.push(k);
}

k = mat;

for(i=1;i < x-1; i++){
    for(b=1;b<y-1;b++){
        if(k[i][b] == "*" && k[i][b+1] == "*" && k[i][b-1] == "*" && k[i-1][b] == "*" && k[i+1][b] == "*"){

            flag = true;
            row_index = i;
            col_index = b;

            loop_b = true;
            break;
        }
    }
    if(loop_b)
        break;
}

loop_b = false;

if(flag){
    for(i=0;i<x;i++){
        for(b=0;b < y;b++){
            if(k[i][b] == "*" && (b != col_index || i != row_index)){

                flag = false;

                loop_b = true;
                break;
            }
        }
        if(loop_b)
            break;
    }
}

if(flag)
    print("YES");
else
    print("NO");

var g = (readline()).split(" ");

var x = Number(g[0]);

var y = Number(g[1]);

var flag = false;

var row_index = 0;
var col_index = 0;
var k = "";

var loop_b = false;

var mat = [];
for(i=0;i<x;i++){
     k = readline().split("");

     mat.push(k);
}

k = mat;

for(i=1;i < x-1; i++){
    for(b=1;b<y-1;b++){
        if(k[i][b] == "*" && k[i][b+1] == "*" && k[i][b-1] == "*" && k[i-1][b] == "*" && k[i+1][b] == "*"){

            flag = true;
            row_index = i;
            col_index = b;

            loop_b = true;
            break;
        }
    }
    if(loop_b)
        break;
}

loop_b = false;

if(flag){
    for(i=0;i<x;i++){
        for(b=0;b < y;b++){
            if(k[i][b] == "*" && (b != col_index && i != row_index)){

                flag = false;

                loop_b = true;
                break;
            }
        }
        if(loop_b)
            break;
    }
}

if(flag)
    print("YES");
else
    print("NO");