function main() {
    var numFriends = parseInt(readline());
    var widthArray = new Array();
    var heightArray = new Array();

    getDimensions(widthArray, heightArray, numFriends);

    var totalW = widthArray.reduce(sum);
    var maxH1 = maxWithout(heightArray, -1);
    var maxH2 = maxWithout(heightArray, maxH1);

    for(var i = 0; i < numFriends; ++i) {
        var h = heightArray[maxH1];
        if(i == maxH1) {
            h = heightArray[maxH2];
        }
        print((totalW - widthArray[i]) * h);
    }

}

function getDimensions(w, h, n) {
    for(var i = 0; i < n; i++) {
        var line = readline();
        var arr = line.split(" ");
        var _w = parseInt(arr[0]);
        var _h = parseInt(arr[1]);
        w.push(_w);
        h.push(_h);
    }
}

var sum = function(previousValue, currentValue, index, array) {
    return previousValue + currentValue;
}

var maxWithout = function(arr, indexToDisregard) {
    var max = 0;
    var maxIndex = 0;
    for(var i = 0; i < arr.length; i++) {
        if(arr[i] > max && i != indexToDisregard) {
            max = arr[i];
            maxIndex = i;
        }
    }
    return maxIndex;
}

main();

//Array snippets
Array.prototype.back = function()
{
    return this[this.length - 1];
}

//Math snippets
//GCD
Math.gcd = function(a, b)
{
    return (b ? gcd(b, a%b) : a);
}

//LCM
Math.lcm = function(a, b)
{
    return (a/gcd(a, b)*b);
}

//Signum
Math.sign = function(a)
{
    return ((a > 0) - (a < 0));
}

//Usual number comparator
Math.cmp = function(a, b)
{
    return (+a > +b) - (+a < +b);
}

//Inverse number comparator
Math.icmp = function(a, b)
{
    return (+a < +b) - (+a > +b);
}

function Stack()
{
    this.a = [];
}

Stack.prototype.empty = function()
{
    return this.a.length == 0;
}

Stack.prototype.push = function(v)
{
    this.a.push(v);
}

Stack.prototype.pop = function()
{
    if (!this.empty())
        return this.a.pop();
    return undefined;
}

Stack.prototype.top = function()
{
    if (!this.empty())
        return this.a[this.a.length - 1];
    return undefined;
}

Stack.prototype.clear = function()
{
    this.a = [];
}

Stack.prototype.size = function()
{
    return this.a.length;
}

function Queue()
{
    this.l = new Stack();
    this.r = new Stack();
}

Queue.prototype.push = function(v)
{
    this.l.push(v);
}

Queue.prototype.empty = function()
{
    return this.r.empty() && this.l.empty();
}

Queue.prototype.pop = function()
{
    if (this.r.empty())
    {
        while(!this.l.empty())
            this.r.push(this.l.pop());
    }
    if (!this.r.empty())
        return this.r.pop();
    return undefined;
}

Queue.prototype.front = function()
{
    if (this.r.empty())
    {
        while(!this.l.empty())
            this.r.push(this.l.pop());
    }
    if (!this.r.empty())
        return this.r.top();
    return undefined;
}

Queue.prototype.size = function()
{
    return l.size() + r.size();
}

Queue.prototype.clear = function()
{
    l.clear();
    r.clear();
}

function Reader()
{
    this.b = [];
    this.c = 0;
}

Reader.prototype.next = function()
{
    if (this.c == this.b.length)
    {
        this.c = 0;
        this.b = readline().split(' ');
    }
    return this.b[this.c++];
}

function Writer()
{
    this.l = [""];
    this.c = 0;
}

Writer.prototype.print = function(s)
{
    this.l[this.c] += s;
}

Writer.prototype.println = function(s)
{
    if (s == undefined)
        s = "";
    this.l[this.c] += s;
    this.l.push("");
    ++this.c;
}

Writer.prototype.flush = function()
{
    print(this.l.join('\n'));
    this.l = [];
}

function Treap(cmp)
{
    if (typeof cmp == "undefined")
        this.cmp = function(a,b){return ((a>b)-(a<b));};
    this.cmp = cmp;
    this._root = null;
}

Treap.Node = function(k, v, p, l, r)
{
    this.k = k;
    this.v = v;
    this.p = p;
    this.l = l;
    this.r = r;
    this.size = 1;
}

Treap.prototype._update = function(n)
{
    if (n)
        n.size = 1 + (n.l?n.l.size:0) + (n.r?n.r.size:0);
}

Treap.prototype._sizeOf = function(n)
{
    return (n?n.size:0);
}

Treap.prototype._split = function(t, k)
{
    if (!t)
        return {l : null, r : null};
    else
    {
        if (this.cmp(k, t.k) < 0)
        {
            var tmp = this._split(t.l, k);
            t.l = tmp.r;
            this._update(t);
            return {l: tmp.l, r: t};
        }
        var tmp = this._split(t.r, k);
        t.r = tmp.l;
        this._update(t);
        return {l : t, r : tmp.r};
    }
}

Treap.prototype._insert = function(t, n)
{
    if (!t)
        return n;
    if (n.p > t.p)
    {
        var tmp = this._split(t, n.k);
        n.l = tmp.l;
        n.r = tmp.r;
        this._update(n);
        return n;
    }
    if (this.cmp(n.k, t.k) < 0)
        t.l = this._insert(t.l, n);
    else
        t.r = this._insert(t.r, n);
    this._update(t);
    return t;
}

Treap.prototype.nth = function(n)
{
    var cur = this._root;
    var lSize = 0;
    while(cur)
    {
        lSize = this._sizeOf(cur.l);
        if (lSize == n)
            return {k: cur.k, v: cur.v};
        cur = lSize > n ? cur.l : cur.r;
        if (lSize < n)
            n -= lSize + 1;
    }
    return null;
}

Treap.prototype._forEach = function(t, cb)
{
    if (t.l)
        this._forEach(t.l, cb);
    cb(t.k, t.v);
    if (t.r)
        this._forEach(t.r, cb);
}

Treap.prototype.forEach = function(cb)
{
    if (this._root)
        this._forEach(this._root, cb);
}

Treap.prototype.insert = function(k, v)
{
    this._root = this._insert(this._root, new Treap.Node(k, v, Math.random(), null, null));
}

Treap.prototype._merge = function(l, r)
{
    if (!l)
    {
        this._update(r);
        return r;
    }
    if (!r)
    {
        this._update(l);
        return l;
    }
    if (l.p > r.p)
    {
        l.r = this._merge(l.r, r)
        this._update(l);
        return l;
    }
    r.l = this._merge(l, r.l);
    this._update(r);
    return r;
}

Treap.prototype._erase = function(t, k)
{
    if (t.k == k)
    {
        var tmp = this._merge(t.l, t.r);
        this._update(tmp);
        return tmp;
    }
    if (this.cmp(k, t.k) <= 0)
        if (t.l)
            t.l = this._erase(t.l, k);
    else
        if (t.r)
            t.r = this._erase(t.r, k);
    this._update(t);
    return t;
}

Treap.prototype.erase = function(k)
{
    if (this._root)
        this._root = this._erase(this._root, k);
}

Treap.prototype._get = function(t, k)
{
    if (!t)
        return undefined;
    if (this.cmp(k, t.k) == 0)
        return t.v;
    if (this.cmp(k, t.k) < 0)
        return this._get(t.l, k);
    return this._get(t.r, k);
}

Treap.prototype.get = function(k)
{
    if (this._root)
        return this._get(this._root, k);
    return undefined;
}

Treap.prototype.set = function(k, v)
{
    var cur = this._root;
    while(cur)
    {
        if (this.cmp(k, cur.k) == 0)
        {
            cur.v = v;
            return;
        }
        if (this.cmp(k, cur.k) < 0)
            cur = cur.l;
        else
            cur = cur.r;
    }
}

Treap.prototype.clear = function()
{
    this._root = null;
}

Treap.prototype.size = function()
{
    return (this._root?this._root.size:0);
}

function Set(cmp)
{
    this.treap = new Treap(cmp);
}

Set.prototype.insert = function(v)
{
    if (this.treap.get(v) == undefined)
        this.treap.insert(v, 1);
}

Set.prototype.size = function()
{
    return this.treap.size();
}

Set.prototype.clear = function()
{
    this.treap.clear();
}

Set.prototype.erase = function(v)
{
    this.treap.erase(v);
}

Set.prototype.count = function(v)
{
    return this.treap.get(v) != undefined;
}

Set.prototype.nth = function(v)
{
    if (v < 0 || v >= this.treap.size())
        return undefined;
    return this.treap.nth(v).k;
}

Set.prototype.first = function()
{
    return this.nth(0);
}

Set.prototype.last = function()
{
    return this.nth(this.size() - 1);
}

Set.prototype.forEach = function(cb)
{
    this.treap.forEach(cb);
}

function MultiSet(cmp)
{
    this.treap = new Treap(cmp);
    this._size = 0;
}

MultiSet.prototype.insert = function(v)
{
    ++this._size;
    var tmp = this.treap.get(v);
    if (tmp == undefined)
        this.treap.insert(v, 1);
    else
        this.treap.set(v, tmp+1);
}

MultiSet.prototype.size = function()
{
    return this._size;
}

MultiSet.prototype.clear = function()
{
    this._size = 0;
    this.treap.clear();
}

MultiSet.prototype.erase = function(v)
{
    var tmp = this.treap.get(v);
    if (tmp != undefined)
    {
        if (tmp == 1)
            this.treap.erase(v);
        if (tmp > 1)
            this.treap.set(v, tmp-1);
        --this._size;
    }
}

MultiSet.prototype.eraseAll = function(v)
{
    this.treap.erase(v);
}

MultiSet.prototype.count = function(v)
{
    var tmp = this.treap.get(v);
    return (tmp == undefined?0:tmp);
}

MultiSet.prototype.first = function()
{
    return this.treap.nth(0).k;
}

MultiSet.prototype.last = function()
{
    return this.treap.nth(this.treap.size() - 1).k;
}

MultiSet.prototype.forEach = function(cb)
{
    this.treap.forEach(function(k, v)
    {
        for(var i = 0; i < v; ++i)
            cb(k);
    });
}

function main(cin, cout)
{
    var n = +cin.next();
    var sum = 0;
    var w = new Array(200100);
    var h = new Array(200100);
    var set = new MultiSet(Math.icmp);
    var tmp;
    for(var i = 0; i < n; ++i)
    {
        w[i] = +cin.next();
        h[i] = +cin.next();
        sum += w[i];
        set.insert(h[i]);
    }
    var W, H;
    for(var i = 0; i < n; ++i)
    {
        W = sum - w[i];
        set.erase(h[i]);
        H = set.first();
        set.insert(h[i]);
        //print(set.count(1));
        //print(set.count(3));
        cout.print(W*H);
        cout.print(" ");
    }
}

var cin = new Reader();
var cout = new Writer();

main(cin, cout);

cout.flush();

//Array snippets
Array.prototype.back = function()
{
    return this[this.length - 1];
}

//Math snippets
//GCD
Math.gcd = function(a, b)
{
    return (b ? gcd(b, a%b) : a);
}

//LCM
Math.lcm = function(a, b)
{
    return (a/gcd(a, b)*b);
}

//Signum
Math.sign = function(a)
{
    return ((a > 0) - (a < 0));
}

//Usual number comparator
Math.cmp = function(a, b)
{
    return (+a > +b) - (+a < +b);
}

//Inverse number comparator
Math.icmp = function(a, b)
{
    return (+a < +b) - (+a > +b);
}

function Stack()
{
    this.a = [];
}

Stack.prototype.empty = function()
{
    return this.a.length == 0;
}

Stack.prototype.push = function(v)
{
    this.a.push(v);
}

Stack.prototype.pop = function()
{
    if (!this.empty())
        return this.a.pop();
    return undefined;
}

Stack.prototype.top = function()
{
    if (!this.empty())
        return this.a[this.a.length - 1];
    return undefined;
}

Stack.prototype.clear = function()
{
    this.a = [];
}

Stack.prototype.size = function()
{
    return this.a.length;
}

function Queue()
{
    this.l = new Stack();
    this.r = new Stack();
}

Queue.prototype.push = function(v)
{
    this.l.push(v);
}

Queue.prototype.empty = function()
{
    return this.r.empty() && this.l.empty();
}

Queue.prototype.pop = function()
{
    if (this.r.empty())
    {
        while(!this.l.empty())
            this.r.push(this.l.pop());
    }
    if (!this.r.empty())
        return this.r.pop();
    return undefined;
}

Queue.prototype.front = function()
{
    if (this.r.empty())
    {
        while(!this.l.empty())
            this.r.push(this.l.pop());
    }
    if (!this.r.empty())
        return this.r.top();
    return undefined;
}

Queue.prototype.size = function()
{
    return l.size() + r.size();
}

Queue.prototype.clear = function()
{
    l.clear();
    r.clear();
}

function Reader()
{
    this.b = [];
    this.c = 0;
}

Reader.prototype.next = function()
{
    if (this.c == this.b.length)
    {
        this.c = 0;
        this.b = readline().split(' ');
    }
    return this.b[this.c++];
}

function Writer()
{
    this.l = [""];
    this.c = 0;
}

Writer.prototype.print = function(s)
{
    this.l[this.c] += s;
}

Writer.prototype.println = function(s)
{
    if (s == undefined)
        s = "";
    this.l[this.c] += s;
    this.l.push("");
    ++this.c;
}

Writer.prototype.flush = function()
{
    print(this.l.join('\n'));
    this.l = [];
}

function Treap(cmp)
{
    if (typeof cmp == "undefined")
        this.cmp = function(a,b){return ((a>b)-(a<b));};
    this.cmp = cmp;
    this._root = null;
}

Treap.Node = function(k, v, p, l, r)
{
    this.k = k;
    this.v = v;
    this.p = p;
    this.l = l;
    this.r = r;
    this.size = 1;
}

Treap.prototype._update = function(n)
{
    if (n)
        n.size = 1 + (n.l?n.l.size:0) + (n.r?n.r.size:0);
}

Treap.prototype._sizeOf = function(n)
{
    return (n?n.size:0);
}

Treap.prototype._split = function(t, k)
{
    if (!t)
        return {l : null, r : null};
    else
    {
        if (this.cmp(k, t.k) < 0)
        {
            var tmp = this._split(t.l, k);
            t.l = tmp.r;
            this._update(t);
            return {l: tmp.l, r: t};
        }
        var tmp = this._split(t.r, k);
        t.r = tmp.l;
        this._update(t);
        return {l : t, r : tmp.r};
    }
}

Treap.prototype._insert = function(t, n)
{
    if (!t)
        return n;
    if (n.p > t.p)
    {
        var tmp = this._split(t, n.k);
        n.l = tmp.l;
        n.r = tmp.r;
        this._update(n);
        return n;
    }
    if (this.cmp(n.k, t.k) < 0)
        t.l = this._insert(t.l, n);
    else
        t.r = this._insert(t.r, n);
    this._update(t);
    return t;
}

Treap.prototype.nth = function(n)
{
    var cur = this._root;
    var lSize = 0;
    while(cur)
    {
        lSize = this._sizeOf(cur.l);
        if (lSize == n)
            return {k: cur.k, v: cur.v};
        cur = lSize > n ? cur.l : cur.r;
        if (lSize < n)
            n -= lSize + 1;
    }
    return null;
}

Treap.prototype._forEach = function(t, cb)
{
    if (t.l)
        this._forEach(t.l, cb);
    cb(t.k, t.v);
    if (t.r)
        this._forEach(t.r, cb);
}

Treap.prototype.forEach = function(cb)
{
    if (this._root)
        this._forEach(this._root, cb);
}

Treap.prototype.insert = function(k, v)
{
    this._root = this._insert(this._root, new Treap.Node(k, v, Math.random()*Math.random(), null, null));
}

Treap.prototype._merge = function(l, r)
{
    if (!l)
    {
        this._update(r);
        return r;
    }
    if (!r)
    {
        this._update(l);
        return l;
    }
    if (l.p > r.p)
    {
        l.r = this._merge(l.r, r)
        this._update(l);
        return l;
    }
    r.l = this._merge(l, r.l);
    this._update(r);
    return r;
}

Treap.prototype._erase = function(t, k)
{
    if (t.k == k)
    {
        var tmp = this._merge(t.l, t.r);
        this._update(tmp);
        return tmp;
    }
    if (this.cmp(k, t.k) <= 0)
        if (t.l)
            t.l = this._erase(t.l, k);
    else
        if (t.r)
            t.r = this._erase(t.r, k);
    this._update(t);
    return t;
}

Treap.prototype.erase = function(k)
{
    if (this._root)
        this._root = this._erase(this._root, k);
}

Treap.prototype._get = function(t, k)
{
    if (!t)
        return undefined;
    if (this.cmp(k, t.k) == 0)
        return t.v;
    if (this.cmp(k, t.k) < 0)
        return this._get(t.l, k);
    return this._get(t.r, k);
}

Treap.prototype.get = function(k)
{
    if (this._root)
        return this._get(this._root, k);
    return undefined;
}

Treap.prototype.set = function(k, v)
{
    var cur = this._root;
    while(cur)
    {
        if (this.cmp(k, cur.k) == 0)
        {
            cur.v = v;
            return;
        }
        if (this.cmp(k, cur.k) < 0)
            cur = cur.l;
        else
            cur = cur.r;
    }
}

Treap.prototype.clear = function()
{
    this._root = null;
}

Treap.prototype.size = function()
{
    return (this._root?this._root.size:0);
}

function Set(cmp)
{
    this.treap = new Treap(cmp);
}

Set.prototype.insert = function(v)
{
    if (this.treap.get(v) == undefined)
        this.treap.insert(v, 1);
}

Set.prototype.size = function()
{
    return this.treap.size();
}

Set.prototype.clear = function()
{
    this.treap.clear();
}

Set.prototype.erase = function(v)
{
    this.treap.erase(v);
}

Set.prototype.count = function(v)
{
    return this.treap.get(v) != undefined;
}

Set.prototype.nth = function(v)
{
    if (v < 0 || v >= this.treap.size())
        return undefined;
    return this.treap.nth(v).k;
}

Set.prototype.first = function()
{
    return this.nth(0);
}

Set.prototype.last = function()
{
    return this.nth(this.size() - 1);
}

Set.prototype.forEach = function(cb)
{
    this.treap.forEach(cb);
}

function MultiSet(cmp)
{
    this.treap = new Treap(cmp);
    this._size = 0;
}

MultiSet.prototype.insert = function(v)
{
    ++this._size;
    var tmp = this.treap.get(v);
    if (tmp == undefined)
        this.treap.insert(v, 1);
    else
        this.treap.set(v, tmp+1);
}

MultiSet.prototype.size = function()
{
    return this._size;
}

MultiSet.prototype.clear = function()
{
    this._size = 0;
    this.treap.clear();
}

MultiSet.prototype.erase = function(v)
{
    var tmp = this.treap.get(v);
    if (tmp != undefined)
    {
        if (tmp == 1)
            this.treap.erase(v);
        if (tmp > 1)
            this.treap.set(v, tmp-1);
        --this._size;
    }
}

MultiSet.prototype.eraseAll = function(v)
{
    this.treap.erase(v);
}

MultiSet.prototype.count = function(v)
{
    var tmp = this.treap.get(v);
    return (tmp == undefined?0:tmp);
}

MultiSet.prototype.first = function()
{
    return this.treap.nth(0).k;
}

MultiSet.prototype.last = function()
{
    return this.treap.nth(this.treap.size() - 1).k;
}

MultiSet.prototype.forEach = function(cb)
{
    this.treap.forEach(function(k, v)
    {
        for(var i = 0; i < v; ++i)
            cb(k);
    });
}

function main(cin, cout)
{
    var n = +cin.next();
    var sum = 0;
    var w = new Array(200100);
    var h = new Array(200100);
    var set = new MultiSet(Math.icmp);
    var tmp;
    for(var i = 0; i < n; ++i)
    {
        w[i] = +cin.next();
        h[i] = +cin.next();
        sum += w[i];
        set.insert(h[i]);
    }
    var W, H;
    for(var i = 0; i < n; ++i)
    {
        W = sum - w[i];
        set.erase(h[i]);
        H = set.first();
        set.insert(h[i]);
        //print(set.count(1));
        //print(set.count(3));
        cout.print(W*H);
        cout.print(" ");
    }
}

var cin = new Reader();
var cout = new Writer();

main(cin, cout);

cout.flush();

var n = parseInt(readline().trim());

var w = new Array();
var h = new Array();

var wsum = 0;

for (var i = 0; i < n; i++) {
    var line = readline().trim().split(' ');
    w[i] = parseInt(line[0]);
    h[i] = parseInt(line[1]);
    wsum += w[i];
}

var max1 = 0;
var max1pos = 0;
var max2 = 0;

for (var i = 0; i < n; i++) {
    if (h[i] > max1) {
        max1 = h[i];
        max1pos = i;
    }
}

for (var i = 0; i < n; i++) {
    if ((h[i] > max2) && (i != max1pos)) {
        max2 = h[i];
    }
}

for (var i = 0; i < n; i++) {
    var wtot = wsum - w[i];
    var htot = 0;
    if (h[i] == max1) {
        htot = max2;
    } else {
        htot = max1;
    }
    write(htot * wtot);
    write(' ');
}

var i = 0,
	sum = 0,
	w = [],
	max = [0, 0],
	imax = 0,
	n = +readline(),
	pixels = [],
	pair;

for (; i<n; i++) {
	pair = readline().split(' ');
	w[i] = +pair[0];
	sum += +pair[0];
	if (+pair[1] > max[0]) {
		imax = i;
		max[1] = max[0];
		max[0] = +pair[1];
	} else if (+pair[1] > max[1]){
		max[1] = +pair[1];
	}
}
for (i=0; i<n; i++) {
	pixels[i] = (sum - w[i]) *
		max[i === imax ? 1 : 0];
}
print(pixels.join(' '));

var n = readline();
var lines = [];

var tmp;
var sum = 0;
for (var i = 0; i < n; i++) {
		tmp = readline().split(' ');
    lines.push([+tmp[0], +tmp[1]]);
    sum += lines[i][0];
}

var maxI = 0;

for (var i = 1; i < n; i++) {
	if (lines[i][1] > lines[maxI][1])	{
		maxI = i;
	}
}

var prevMaxI = maxI === 0 ? 1 : 0;

for (var i = prevMaxI + 1; i < maxI; i++) {
	if (lines[i][1] > lines[prevMaxI][1])	{
		prevMaxI = i;
	}
}

for (var i = maxI + 1; i < n; i++) {
	if (lines[i][1] > lines[prevMaxI][1])	{
		prevMaxI = i;
	}
}

var output = [];

for (var i = 0; i < n; i++) {
    output.push(sumPixels(lines, i));
}

function sumPixels(arr, index) {
    var sumW;

    sumW = sum - arr[index][0];

    var maxH = index === maxI ? arr[prevMaxI][1] : arr[maxI][1];

    return maxH * sumW;
}

print(output.join(' '));

	var n = readline(),
		friends = [],
		sizes = [],
		sumWidths = 0,
		maxHeight = {
			value: 0
		}
		secondHeight = {
			value: 0
		}

	for (var i=0; i < n; i++) {
		var line = readline().split(' ');
		line[0] = Number(line[0]);
		line[1] = Number(line[1]);
		friends[i] = line[0];
		sumWidths += line[0];
		if (line[1] >= maxHeight.value) {
			secondHeight.value = maxHeight.value;
			maxHeight.value = line[1];
			maxHeight.id = i;
		}

		if (line[1] < maxHeight.value && line[1] > secondHeight.value) {
			secondHeight.value = line[1];
		}
	}

	for (var i = 0; i < n; i++) {
		if (i != maxHeight.id) {
			var height = maxHeight.value;
		} else {
			var height = secondHeight.value;
		}
		sizes[i] = height * (sumWidths - friends[i]);
	}

	print(sizes.join(' '));

var output = "";
var people = [];
var n = parseInt(readline());
var width = 0;
var height = 0;
for (var i = n; i > 0; i--) {
    var line = readline().split(" ");
    var w = parseInt(line[0]);
    var h = parseInt(line[1]);
    width += w;
    if (height < h) {
        height = h;
    }
    people.push({
        width: w,
        height: h
    });
}
for (var i = 0; i < n; i++) {
    var cw = width - people[i].width;
    var ch = height;
    if (ch === people[i].height) {
        ch = 0;
        for (var j = 0; j < n; j++) {
            if (i === j) continue;
            if (ch < people[j].height) {
                ch = people[j].height;
                if (ch === height) {
                    break;
                }
            }
        }
    }
    output += (cw * ch) + " ";
}
print(output);

var n = readline().trim();

var w = new Array();
var h = new Array();

var wsum = 0;

for (var i = 0; i < n; i++) {
    var line = readline().trim().split(' ');
    w[i] = line[0];
    h[i] = line[0];
    wsum += w[i];
}

var max1 = 0;
var max1pos = 0;
var max2 = 0;

for (var i = 0; i < n; i++) {
    if (h[i] > max1) {
        max1 = h[i];
        max1pos = i;
    }
}

for (var i = 0; i < n; i++) {
    if ((h[i] > max2) && (i != max1pos)) {
        max2 = h[i];
    }
}

for (var i = 0; i < n; i++) {
    var wtot = wsum - w[i];
    var htot = 0;
    if (h[i] == max1) {
        htot = max2;
    } else {
        htot = max1;
    }
    write(htot * wtot);
    write(' ');
}

var n = readline();
var lines = [];

var tmp;
var sum = 0;
for (var i = 0; i < n; i++) {
		tmp = readline().split(' ');
    lines.push([+tmp[0], +tmp[1]]);
    sum += lines[i][0];
}

var maxI = 0;
var prevMaxI = 1;

for (var i = 1; i < n; i++) {
	if (lines[i][1] >= lines[maxI][1])	{
		prevMaxI = maxI;
		maxI = i;
	}
}

// var copy = lines.slice();
// copy.sort(function(a, b) {
// 	return b[1] - a[1];
// });

var output = [];

for (var i = 0; i < n; i++) {
    output.push(sumPixels(lines, i));
}

function sumPixels(arr, index) {
    var sumW;

    // arr.forEach( function(wh, i) {
    //     if (i == index) {
    //         sumW += wh[0];
    //     }
    // });

    sumW = sum - arr[index][0];

    var maxH = index === maxI ? arr[prevMaxI][1] : arr[maxI][1];

    return maxH * sumW;
}

print(output.join(' '));

var n = readline();
var lines = [];

var tmp;
var sum = 0;
for (var i = 0; i < n; i++) {
		tmp = readline().split(' ');
    lines.push([+tmp[0], +tmp[1]]);
    sum += lines[i][0];
}

var maxI = 0;

for (var i = 1; i < n; i++) {
	if (lines[i][1] > lines[maxI][1])	{
		maxI = i;
	}
}

var prevMaxI = maxI === 0 ? 1 : 0;

for (var i = prevMaxI + 1; i < maxI; i++) {
	if (lines[i][1] > lines[prevMaxI][1])	{
		prevMaxI = i;
	}
}

for (var i = maxI + 1; i < n; i++) {
	if (lines[i][1] > lines[prevMaxI][1])	{
		prevMaxI = i;
	}
}

print("Max: " + lines[maxI]);
print("PrevMax: " + lines[prevMaxI]);

var output = [];

for (var i = 0; i < n; i++) {
    output.push(sumPixels(lines, i));
}

function sumPixels(arr, index) {
    var sumW;

    sumW = sum - arr[index][0];

    var maxH = index === maxI ? arr[prevMaxI][1] : arr[maxI][1];

    return maxH * sumW;
}

print(output.join(' '));

var n = readline();
var lines = [];

var tmp;
for (var i = 0; i < n; i++) {
		tmp = readline().split(' ');
    lines.push([+tmp[0], +tmp[1]]);
}

lines.sort(function(a, b) {
	return b[1] - a[1];
});

var output = [];

for (var i = 0; i < n; i++) {
    output.push(sumPixels(lines, i));
}

function sumPixels(arr, index) {
    var sumW = 0;

    arr.forEach( function(wh, i) {
        if (i != index) {
            sumW += wh[0];
        }
    });

    var maxH = index === 0 ? arr[1][1] : arr[0][1];

    return maxH * sumW;
}

print(output.join(' '));

var n = readline();
var lines = [];

var tmp;
for (var i = 0; i < n; i++) {
		tmp = readline().split(' ');
    lines.push([+tmp[0], +tmp[1]]);
}

var maxI = 0;
var prevMaxI = 1;

for (var i = 1; i < n; i++) {
	if (lines[i][1] > lines[maxI][1])	{
		prevMaxI = maxI;
		maxI = i;
	}
}

var output = [];

for (var i = 0; i < n; i++) {
    output.push(sumPixels(lines, i));
}

function sumPixels(arr, index) {
    var sumW = 0;

    arr.forEach( function(wh, i) {
        if (i != index) {
            sumW += wh[0];
        }
    });

    var maxH = index === maxI ? arr[prevMaxI][1] : arr[maxI][1];

    return maxH * sumW;
}

print(output.join(' '));

var n = readline();
var lines = [];

var tmp;
var sum = 0;
for (var i = 0; i < n; i++) {
		tmp = readline().split(' ');
    lines.push([+tmp[0], +tmp[1]]);
    sum += lines[i][0];
}

var maxI = 0;

for (var i = 1; i < n; i++) {
	if (lines[i][1] > lines[maxI][1])	{
		maxI = i;
	}
}

var prevMaxI = 0;

for (var i = 1; i < maxI; i++) {
	if (lines[i][1] > lines[prevMaxI][1])	{
		prevMaxI = i;
	}
}

for (var i = maxI + 1; i < n; i++) {
	if (lines[i][1] > lines[prevMaxI][1])	{
		prevMaxI = i;
	}
}

var output = [];

for (var i = 0; i < n; i++) {
    output.push(sumPixels(lines, i));
}

function sumPixels(arr, index) {
    var sumW;

    sumW = sum - arr[index][0];

    var maxH = index === maxI ? arr[prevMaxI][1] : arr[maxI][1];

    return maxH * sumW;
}

print(output.join(' '));

var n = readline(),
	friends = [],
	sizes = [],
	sumWidths = 0;

for (var i=0; i < n; i++) {
	var line = readline().split(' ');
	friends.push({width: line[0], height: line[1]});
	sumWidths += line[0];
}

for (var i = 0; i < n; i++) {
	maxHeight = 0;
	for (var j = 0; j < n; j++) {
		if (j!=i) {
			if (friends[j].height > maxHeight) {
				maxHeight = friends[j].height;
			}
		}
	}
	sizes[i] = maxHeight * (sumWidths - friends[i].width);
}

print(sizes.join(' '));

var n = readline(),
	friends = [],
	sizes = [],
	sumWidths = 0,
	maxHeight = {
		value: 0
	}
	secondHeight = {
		value: 0
	}

for (var i=0; i < n; i++) {
	var line = readline().split(' ');
	line[0] = Number(line[0]);
	line[1] = Number(line[1]);
	friends[i] = line[0];
	sumWidths += line[0];
	if (line[1] > maxHeight.value) {
		secondHeight.value = maxHeight.value;
		secondHeight.id = maxHeight.id;
		maxHeight.value = line[1];
		maxHeight.id = i;
	}
	if (line[1] < maxHeight.value && line[1] > secondHeight.value) {
		secondHeight.value = line[1];
		secondHeight.id = i;
	}
}

for (var i = 0; i < n; i++) {
	if (i != maxHeight.id) {
		var height = maxHeight.value;
	} else {
		var height = secondHeight.value;
	}
	sizes[i] = height * (sumWidths - friends[i]);
}

print(sizes.join(' '));

var n = readline(),
	friends = [],
	sizes = [],
	sumWidths = 0,
	maxHeight = {
		value: 0
	}
	secondHeight = {
		value: 0
	}

for (var i=0; i < n; i++) {
	var line = readline().split(' ');
	line[0] = Number(line[0]);
	line[1] = Number(line[1]);
	friends.push({width: line[0], height: line[1]});
	sumWidths += line[0];
	if (line[1] > maxHeight.value) {
		secondHeight.value = maxHeight.value;
		secondHeight.id = maxHeight.id;
		maxHeight.value = line[1];
		maxHeight.id = i;
	}
	if (line[1] < maxHeight.value && line[1] > secondHeight.value) {
		secondHeight.value = line[1];
		secondHeight.id = i;
	}
}

for (var i = 0; i < n; i++) {
	if (i != maxHeight.id) {
		var height = maxHeight.value;
	} else {
		var height = secondHeight.value;
	}
	sizes[i] = height * (sumWidths - friends[i].width);
}

print(sizes.join(' '));

var n = readline(),
	sizes = [],
	widths = [],
	sumWidths = 0,
	maxHeight = 0;

for (var i=0; i < n; i++) {
	var line = readline().split(' ');
	sumWidths += line[0];
	widths[i] = line[0];
	if (maxHeight < line[1]) {
		maxHeight = line[1];
	}
}

for (var i = 0; i< n; i++) {
	sizes[i] = (sumWidths - widths[i])*maxHeight;
}

print(sizes.join(' '));

var n = readline(),
	friends = [],
	sizes = [],
	sumWidths = 0,
	maxHeight = {
		value: 0
	}
	secondHeight = {
		value: 0
	}

for (var i=0; i < n; i++) {
	var line = readline().split(' ');
	friends.push({width: line[0], height: line[1]});
	sumWidths += line[0];
	if (line[1] > maxHeight.value) {
		secondHeight.value = maxHeight.value;
		secondHeight.id = maxHeight.id;
		maxHeight.value = line[1];
		maxHeight.id = i;
	}
}

for (var i = 0; i < n; i++) {
	if (i != maxHeight.id) {
		var height = maxHeight.value;
	} else {
		var height = secondHeight.value;
	}
	sizes[i] = height * (sumWidths - friends[i].width);
}

print(sizes.join(' '));


const readline = require('readline')

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

function solve(n, arr) {
    const r = Array(n)
    let m = 0
    let sorted = arr.map((x, i) => [x, i])
    for (let i = 0; i < n; i++) {
        sorted.sort((a, b) => b[0] - a[0])
        if (sorted[0][0] === 0) {
        // console.log(r, sorted)
            for (let j = 0; j < sorted.length; j++) {
                r[i++] = arr[sorted[j][1]]
            }
            break
        }
        r[i] = arr[sorted.shift()[1]]
        //
        m |= r[i]
        sorted = sorted.map(([x, i]) => [~m & x, i])
        // console.log(sorted)
    }
    return r.join(' ')
}

'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(),
        a = rns(n);
  a.sort((a, b) => b - a);
  const res = [a[0]],
        vis = [1];
  let pre = res[0];
  let N = 30;
  while (!(pre & 1 << N)) N--;
  for (let i = N; i >= 0; i--) {
    if (pre & 1 << i) continue;
    let max = -1,
        t = -1;
    for (let j = 0; j < n; j++) {
      if (vis[j] || !(a[j] & 1 << i)) continue;
      if (max === -1 || max < (pre | a[j])) {
        max = pre | a[j];
        t = j;
      }
    }
    if (t !== -1) {
      res.push(a[t]);
      vis[t] = 1;
      pre |= a[t];
    }
  }
  for (let i = 0; i < n; i++) {
    if (vis[i]) continue;
    res.push(a[i]);
  }
  return res.join(' ');
}
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);
}();

'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(),
        a = rns(n);
  a.sort((a, b) => b - a);
  const res = [a[0]],
        vis = [1];
  let pre = res[0];
  let N = 30;
  while (!(pre & 1 << N)) N--;
  for (let i = N; i >= 0; i--) {
    if (pre & 1 << i) continue;
    let max = -1,
        t = -1;
    for (let j = 0; j < n; j++) {
      if (vis[j] || !(a[j] & 1 << i)) continue;
      if (max === -1 || max < (pre | a[j])) {
        max = pre | a[j];
        t = j;
      }
    }
    if (t !== -1) {
      res.push(a[t]);
      vis[t] = 1;
    }
  }
  for (let i = 0; i < n; i++) {
    if (vis[i]) continue;
    res.push(a[i]);
  }
  return res.join(' ');
}
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);
}();

'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(),
        a = rns(n);
  a.sort((a, b) => b - a);
  const res = [a[0]],
        vis = [1];
  let pre = res[0];
  let N = 30;
  while (!(pre & 1 << N)) N--;
  for (let i = N; i >= 0; i--) {
    if (pre & 1 << i) continue;
    let max = -1,
        t = -1;
    for (let j = 0; j < n; j++) {
      if (vis[j]) continue;
      if (max === -1 || max < (pre | a[j])) {
        max = pre | a[j];
        t = j;
      }
    }
    if (t !== -1) {
      res.push(a[t]);
      vis[t] = 1;
    }
  }
  for (let i = 0; i < n; i++) {
    if (vis[i]) continue;
    res.push(a[i]);
  }
  return res.join(' ');
}
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);
}();


function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return mid;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  let sub = [];
  a = a || 0;
  b = b || (this.length - 1);
  for (let i = a; i <= b; i++) {
    sub.push(this[i])
    if (fn(this[i], i, this)) {
      arr.push(sub);
      sub = [];
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
let MOD = 998244353
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);
  return (u + MOD) % MOD;
}

// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let [n, m, q] = $(3), v = Arr(n, i => ({ i, p: $() })), e = Arr(m, i => ({ u: $(), v: $() })), qe = Arr(q, i => ({ t: $(), x: $() }))
  qe.forEach(q => q.t == 2 ? e[q.x - 1].d = 1 : 0)
  v.forEach(v => v.la = v)
  let par = Array(n).fill(-1);
  let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
  let dsu = (x, y) => {
    if ((x = root(x)) == (y = root(y))) return;
    if (par[y] < par[x]) [x, y] = [y, x];
    par[x] += par[y];
    par[y] = x;
    v[x].la.ne = v[y];
    v[x].la = v[y].la;
    return v[y];
  }
  // log(e);
  e.forEach(e => {
    if (e.d) return;
    dsu(e.u - 1, e.v - 1);
  })
  // log(par)
  ForR(q, i => {
    if (qe[i].t == 1) {
      qe[i].x = v[root(qe[i].x - 1)];
      qe[i].y = qe[i].x.la;
    } else {
      dsu(e[qe[i].x - 1].u - 1, e[qe[i].x - 1].v - 1)
    }
  })
  // log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))
  let mark = Array(n);
  let c = 0;
  For(n, i => {
    if (mark[i]) return;
    let x = root(i);
    let cur = v[x];
    while (cur) {
      mark[cur.i] = 1;
      cur.i = c++;
      cur = cur.ne;
    }
  })
  // log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))
  let v2 = v.slice().sort((v1, v2) => v1.i - v2.i);
  // log(v2.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))
  let n2 = 1 << Math.ceil(Math.log2(n))
  let it = Array(n2 + n2);
  For(n2, n2 + n2 - 1, i => { it[i] = i - n2 < n ? i - n2 : -1 });
  ForR(n2 - 1, 1, i => {
    let p1 = it[i << 1] < 0 ? -1 : v2[it[i << 1]].p;
    let p2 = it[i << 1 | 1] < 0 ? -1 : v2[it[i << 1 | 1]].p
    it[i] = p1 >= p2 ? it[i << 1] : it[i << 1 | 1];
  })

  let query = (l, r) => {  //[l, r)
    let res = l;
    for (l += n2, r += n2; l < r; l >>= 1, r >>= 1) {
      if (l & 1) { if (v2[res].p < v2[it[l]].p) res = it[l]; l++ }
      if (r & 1) { r--; if (v2[res].p < v2[it[r]].p) res = it[r] }
    }
    return res;
  }
  let update = i => {
    if (v2[i].p == 0) return;
    v2[i].p = 0;
    i = (i + n2) >> 1;
    while (i) {
      let p1 = it[i << 1] < 0 ? -1 : v2[it[i << 1]].p;
      let p2 = it[i << 1 | 1] < 0 ? -1 : v2[it[i << 1 | 1]].p
      it[i] = p1 >= p2 ? it[i << 1] : it[i << 1 | 1];
      i >>= 1;
    }
  }
  qe.forEach(q => {
    if (q.t == 2) return;
    let imax = query(q.x.i, q.y.i + 1);
    // log(q.x.i, q.y.i, imax);
    out.push(v2[imax].p)
    update(imax);
  })
  log(out.join('\n'))
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return mid;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  let sub = [];
  a = a || 0;
  b = b || (this.length - 1);
  for (let i = a; i <= b; i++) {
    sub.push(this[i])
    if (fn(this[i], i, this)) {
      arr.push(sub);
      sub = [];
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
let MOD = 998244353
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);
  return (u + MOD) % MOD;
}

// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let [n, m, q] = $(3), v = Arr(n, i => ({ i, p: $() })), e = Arr(m, i => ({ u: $(), v: $() })), qe = Arr(q, i => ({ t: $(), x: $() }))
  qe.forEach(q => q.t == 2 ? e[q.x - 1].d = 1 : 0)
  v.forEach(v => v.la = v)
  let par = Array(n).fill(-1);
  let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
  let dsu = (x, y) => {
    if ((x = root(x)) == (y = root(y))) return;
    if (par[y] < par[x]) [x, y] = [y, x];
    par[x] += par[y];
    par[y] = x;
    v[x].la.ne = v[y];
    v[x].la = v[y].la;
  }
  // log(e);
  e.forEach(e => e.d ? 0 : dsu(e.u - 1, e.v - 1))
  // log(par)
  qe.forR(q - 1, 0, q => {
    if (q.t == 1) {
      q.x = v[root(q.x - 1)];
      q.y = q.x.la;
    } else {
      dsu(e[q.x - 1].u - 1, e[q.x - 1].v - 1)
    }
  })
  // log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))
  let v2 = [], c = 0;
  For(n, i => {
    if (v[i].i2 != null) return;
    let cur = v[root(i)];
    while (cur) {
      cur.i2 = c++;
      v2.push(cur);
      cur = cur.ne;
    }
  })
  // log(v2.map(v => ({ i: v.i, p: v.p, i2: v.i2 })))
  let n2 = 1 << Math.ceil(Math.log2(n))
  let it = Array(n2 + n2);
  For(n2, n2 + n2 - 1, i => { it[i] = i - n2 < n ? i - n2 : -1 });
  let update = i => {
    let p1 = it[i << 1] < 0 ? -1 : v2[it[i << 1]].p;
    let p2 = it[i << 1 | 1] < 0 ? -1 : v2[it[i << 1 | 1]].p
    it[i] = p1 >= p2 ? it[i << 1] : it[i << 1 | 1];
  }
  ForR(n2 - 1, 1, i => update(i))
  let query = (l, r) => {  //[l, r)
    let res = l;
    for (l += n2, r += n2; l < r; l >>= 1, r >>= 1) {
      if (l & 1) { if (v2[res].p < v2[it[l]].p) res = it[l]; l++ }
      if (r & 1) { r--; if (v2[res].p < v2[it[r]].p) res = it[r] }
    }
    return res;
  }
  let set = i => {
    if (v2[i].p == 0) return;
    v2[i].p = 0;
    i = (i + n2) >> 1;
    while (i) (update(i), i >>= 1)
  }
  qe.forEach(q => {
    if (q.t == 2) return;
    let imax = query(q.x.i2, q.y.i2 + 1);
    // log(q.x.i2, q.y.i2, imax);
    out.push(v2[imax].p)
    set(imax);
  })
  log(out.join('\n'))
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return mid;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  let sub = [];
  a = a || 0;
  b = b || (this.length - 1);
  for (let i = a; i <= b; i++) {
    sub.push(this[i])
    if (fn(this[i], i, this)) {
      arr.push(sub);
      sub = [];
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
let MOD = 998244353
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);
  return (u + MOD) % MOD;
}

// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let [n, m, q] = $(3), v = Arr(n, i => ({ i, p: $() })), e = Arr(m, i => ({ u: $(), v: $() })), qe = Arr(q, i => ({ t: $(), x: $() }))
  qe.forEach(q => q.t == 2 ? e[q.x - 1].d = 1 : 0)
  v.forEach(v => v.la = v)
  let par = Array(n).fill(-1);
  let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
  let dsu = (x, y) => {
    if ((x = root(x)) == (y = root(y))) return;
    if (par[y] < par[x]) [x, y] = [y, x];
    par[x] += par[y];
    par[y] = x;
    v[x].la.ne = v[y];
    v[x].la = v[y].la;
    return v[y];
  }
  // log(e);
  e.forEach(e => {
    if (e.d) return;
    dsu(e.u - 1, e.v - 1);
  })
  // log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))
  e.forR(m - 1, 0, e => {
    if (!e.d) return;
    e.v = dsu(e.u - 1, e.v - 1)
  })
  // log(e)
  // log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))
  let mark = Array(n);
  let c = 0;
  For(n, i => {
    if (mark[i]) return;
    let x = root(i);
    let cur = v[x];
    while (cur) {
      mark[cur.i] = 1;
      cur.i = c++;
      cur = cur.ne;
    }
  })
  // log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))
  v2 = v.slice().sort((v1, v2) => v1.i - v2.i);
  let np = Array(n)
  // log(v.map(v => ({ i: v.i, p: v.p })))
  let st = 0
  v2.cut(v => !v.ne).forEach(a => {
    For(a.length, i => { np[st + i] = new Node(st + i, st + a.length - 1, st) })
    st += a.length;
  })
  // log(np)
  let t = new SplayTree().load(np);
  // t.print()
  qe.forEach(q => {
    if (q.t == 1) {
      let key = v[q.x - 1].i;
      t.splayKey(key);
      let imin = t.root.imin;
      let imax = t.root.imax;
      t.splayKey(imin); let leftNode = t.root.left; t.root.left = undefined; t.root.update();
      t.splayKey(imax); let rightNode = t.root.right; t.root.right = undefined; t.root.update();
      // log(imin, imax, t.root.keymax)
      // log(v2[t.root.keymax].p);
      out.push(v2[t.root.keymax].p)
      if (v2[t.root.keymax].p) {
        v2[t.root.keymax].p = 0;
        t.update(t.root.keymax);
      }
      // t.print()
      t.root.right = rightNode; t.root.update();
      // t.print()
      t.splayKey(imin); t.root.left = leftNode; t.root.update();
      // t.print()
    } else {
      if (!e[q.x - 1].v) return;
      let x = e[q.x - 1].v.i - 1;
      t.splayKey(x);
      let imin = t.root.imin;
      let imax = t.root.imax;
      // log(x, imin, imax);
      t.splayKey(imin); let leftNode = t.root.left; t.root.left = undefined; t.root.update();
      t.splayKey(imax); let rightNode = t.root.right; t.root.right = undefined; t.root.update();
      t.splayKey(x);
      t.root.right.lzimin = x + 1;
      t.root.imax = x;
      if (t.root.left) t.root.left.lzimax = x;
      t.splayKey(imax); t.root.right = rightNode; t.root.update();
      t.splayKey(imin); t.root.left = leftNode; t.root.update();
      // t.print()
    }
  })
  log(out.join('\n'))
  // log(out.length)
}
var v2;

class Node {
  left; right; key; keymax; imax; imin; lzimax; lzimin; iimax; iimin;
  constructor(key, imax, imin) {
    this.key = key;
    this.keymax = key;
    this.imax = imax;
    this.imin = imin;
    this.iimax = imax;
    this.iimin = imin;
  }
  update() {
    this.keymax = this.key;
    this.iimax = this.imax;
    this.iimin = this.imin;
    if (this.left) {
      if (v2[this.left.keymax].p > v2[this.keymax].p) this.keymax = this.left.keymax;
      if (this.left.iimax > this.iimax) this.iimax = this.left.iimax;
      if (this.left.iimin < this.iimin) this.iimin = this.left.iimin;
    }
    if (this.right) {
      if (v2[this.right.keymax].p > v2[this.keymax].p) this.keymax = this.right.keymax;
      if (this.right.iimax > this.iimax) this.iimax = this.right.iimax;
      if (this.right.iimin < this.iimin) this.iimin = this.right.iimin;
    }
  }
  toString() {
    return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.keymax},${this.imin},${this.imax},${this.iimin},${this.iimax})` + (this.right ? ' ' + this.right.toString() : '')
  }
}

class SplayTree {
  root;
  constructor(node) {
    this.root = node;
    return this;
  }

  uptree(x, p, g) {
    if (!g) {
      // lazy update p, x
      if (p.left == x) {
        p.left = x.right;
        x.right = p;
      } else {
        p.right = x.left;
        x.left = p;
      }
      p.update(); x.update();
      return x;
    }
    // lazy update g, p, x
    if (g.left == p && p.left == x) {
      g.left = p.right;
      p.right = g;
      p.left = x.right;
      x.right = p;
    } else if (g.right == p && p.right == x) {
      g.right = p.left;
      p.left = g;
      p.right = x.left;
      x.left = p;
    } else if (g.left == p) {
      p.right = x.left;
      x.left = p;
      g.left = x.right;
      x.right = g;
    } else {
      p.left = x.right;
      x.right = p;
      g.right = x.left;
      x.left = g;
    }
    g.update(); p.update(); x.update();
    return x;
  }

  lazy(trace) {
    trace.forEach(node => {
      if (node.lzimax != undefined) {
        node.imax = node.lzimax;
        if (node.left) node.left.lzimax = node.lzimax;
        if (node.right) node.right.lzimax = node.lzimax;
        node.lzimax = undefined;
      }
      if (node.lzimin != undefined) {
        node.imin = node.lzimin;
        if (node.left) node.left.lzimin = node.lzimin;
        if (node.right) node.right.lzimin = node.lzimin;
        node.lzimin = undefined;
      }
    })
  }

  splay(trace) {
    this.lazy(trace)
    var x = trace.pop();
    while (true) {
      var p = trace.pop();
      var g = trace.pop();
      if (!p) return this.root = x;
      if (!g || !trace.length) return this.root = this.uptree(x, p, g);
      if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);
      else trace[trace.length - 1].right = x = this.uptree(x, p, g);
    }
  }

  insert(key, imax, imin) {
    if (!this.root) return this.root = new Node(key, imax, imin);
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      cur = key < cur.key ? cur.left : cur.right;
    }
    cur = trace[trace.length - 1];
    if (key < cur.key) trace.push(cur.left = new Node(key, imax, imin));
    else trace.push(cur.right = new Node(key, imax, imin));
    this.splay(trace);
  }

  join(tree) {
    if (!this.root) return this.root = tree.root;
    var trace = [this.root];
    var cur = this.root;
    while (cur.right) trace.push(cur = cur.right);
    this.splay(trace);
    this.root.right = tree.root;
    this.root.update();
  }

  splayKey(key) {
    if (!this.root) return;
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      if (cur.key == key) break;
      cur = key < cur.key ? cur.left : cur.right;
    }
    if (trace[trace.length - 1].key != key) return;
    this.splay(trace);
  }

  update(key) {
    if (!this.root) return;
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      if (cur.key == key) break;
      cur = key < cur.key ? cur.left : cur.right;
    }
    if (trace[trace.length - 1].key != key) return;
    this.lazy(trace)
    trace.reverse().forEach(node => node.update())
  }

  load(nodes) {
    if (!nodes.length) return;
    this.root = nodes[0];
    let s = 1, k = 1;
    while (s < nodes.length) {
      let end = Math.min(s + k, nodes.length - 1);
      for (let i = end - 1; i >= s; i--) {
        nodes[i].right = nodes[i + 1];
        nodes[i].update();
      }
      this.root = nodes[s];
      this.root.left = nodes[s - k];
      this.root.update()
      s += ++k;
    }
    return this;
  }

  print() {
    console.log(this.root ? this.root.toString() : undefined);
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
let MOD = 998244353
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);
  return (u + MOD) % MOD;
}
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let [n, m, q] = $(3), v = Arr(n, i => ({ i, p: $() })), e = Arr(m, i => ({ u: $(), v: $() })), qe = Arr(q, i => ({ t: $(), x: $() }))
  qe.forEach(q => q.t == 2 ? e[q.x - 1].d = 1 : 0)
  v.forEach(v => v.fi = v.la = v)
  let par = Array(n).fill(-1);
  let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
  let merge = (x, y) => {
    if ((x = root(x)) == (y = root(y))) return;
    if (par[y] < par[x]) [x, y] = [y, x];
    par[x] += par[y];
    par[y] = x;
    v[x].la.ne = v[y];
    v[x].la = v[y].fi
  }
  e.forEach(e => {
    if (e.d) return;
    merge(e.u - 1, e.v - 1);
  })
  log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))
  e.forR(m - 1, 0, e => {
    if (!e.d) return;
    merge(e.u - 1, e.v - 1);
  })
  log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))
}


//↓見なくていいよ！ここから--------------------------------------------------
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 = new Date();
  Main();
  var end = new Date() - 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){
  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 myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
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;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = [];
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var x = one[0];
		var y = one[1];
		var z = one[2];
		if(x == z && x != y && y != z){
			if(y < x){
				output.push("YES");
				var a = x;
				output.push(y + " " + x + " " + y);
			}else{
				output.push("NO");
			}

		}else if(x == y && y == z && z == x){
			output.push("YES");
			output.push(x + " " + x + " " + x);
		}else if(x != y && x != z && y == z){
			if(x < y){
				output.push("YES");
				output.push(x + " " + x + " " + z);
			}else{
				output.push("NO");
			}
		}else if(x == y && x != z && y != z){
			if(x > z){
				output.push("YES");
				output.push(x + " " + z + " " + z);
			}else{
				output.push("NO");
			}
		}else{
			output.push("NO");
		}
	}
	myout(myconv(output,9));
}

const readline = require('readline');

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

var lineCount = 0
var testCount = 0
var outputStr = ''

rl.on('line', (input) => {
    if (lineCount == 0) {
        // first line
        testCount = parseInt(input)
    }
    else if (lineCount >= testCount) {
        outputStr += getWinner(input) + '\n'
        console.log(outputStr)
        rl.close()
    }
    else {
        // data
        outputStr += getWinner(input) + '\n'
    }
    lineCount++
});

function getWinner(str) {
    var list = str.split(' ')
    var x = list[0]
    var y = list[1]
    var z = list[2]

    var max = Math.max(x, y, z)
    var min = Math.min(x, y, z)

    var maxcount= 0, mincount = 0
    if(x==max){
        maxcount+=1
    }
    if(y==max){
        maxcount+=1
    }
    if(z==max){
        maxcount+=1
    }

    if(maxcount<2){
        return 'NO'
    }

    else{
        return `YES
${max} ${min} ${min}`
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
  const t = Number(readLine())
  for (let i = 0; i < t; i++) {
    const [x, y, z] = readLine().split(/\s/).map(Number).sort((a, b) => b - a)
    if (x !== y) {
      console.log('NO')
      continue
    }
    console.log('YES')
    console.log(`${x} ${z} ${z}`)
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
	const testcases = parseInt(readline());
	for (let i = 0; i < testcases; i++) {
		const [x,y,z] = readline().split(' ').map(i => parseInt(i));
		let e = false
		if (x == y && x == z && y == z) {
			e = true
			console.log('YES')
			console.log(x,y,z)
		}
		if (x == y && z < x) {
			e = true
			console.log('YES')
			console.log(x,z,1)
		}
		if (x == z && y < x) {
			e = true
			console.log('YES')
			console.log(x,y,1)
		}
		if (y == z && x < z) {
			e = true
			console.log('YES')
			console.log(y,x,1)
		}
		if(!e) {
			console.log('NO')
		}
	}
}

const processData = (lines) => {
    let acc = 0
    const n = +lines[acc++]
    for (let i=0; i<n; i++) {
        const [x, y, z] = lines[acc++].split(' ').map(x => +x).sort((a, b) => b - a)

        let unequal = 0
        if (x !== y) {
            unequal++
        }

        if (unequal) {
            console.log('NO')
        } else {
            console.log('YES')
            console.log(x, z, z)
        }
    }

}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
    processData(lines)
})

function solve() {
   var arr = readArray(Number);
   arr.sort(sortF);
   if (arr[1] !== arr[2]) {
      write('NO');
      return;
   }
   arr[1] = arr[0];
   write('YES');
   write(arr.join(' '));
}

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 {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

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

      RL.on('close', 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();
}

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

rl.question("", function (n) {
  functions();
})

function functions() {
  rl.question('', function (input) {
    var n = input.split(' ');
    var x = parseInt(n[0]);
    var y = parseInt(n[1]);
    var z = parseInt(n[2]);
    var a, b, c, bool = false;
    if (x == y && y >= z) {
      bool = true;
      a = x;
      b = z;
      c = 1;
    } else if (x == z && z >= y) {
      bool = true;
      b = x;
      a = y;
      c = 1;
    } else if (y == z && z >= x) {
      bool = true;
      c = y;
      b = x;
      a = 1;
    } else if (x == y && y == z) {
      bool = true;
      a = b = c = x;
    }
    if (bool) {
      console.log('yes')
      console.log(a, b, c)
    } else {
      console.log('no')
    }
    // console.log(x == y, x > z, z, y > 2)
    functions();
  })
}
// function functions() {
//   rl.question("", function (n) {
//     rl.question("", function (num) {
//       var arr = num.split(' ');
//       var l = [];
//       for (var i = 0; i < n * 2; i++) {
//         for (var j = 0; j < arr.length; j++) {
//           var lhas = l.includes(arr[j])
//           if (!lhas) {
//             l.push(arr[j]);
//
//           }
//         }
//       }
//       console.log(l.join(' '));
//       functions();
//     });
//   })
// }
// rl.question('', function (o) {
//   rl.question('', function (n) {
//     rl.question('', function (a) {
//       rl.question('', function (b) {
//         var s = 0;
//         var sa = a.split(' ');
//         var sb = b.split(' ');
//         // console.log(n, newA, s, sa, sb)
//         for (var i = 0; i < n; i++) {
//           var newA = [];
//           var ai = sa[i] - Math.min.apply(Math, sa)
//           var bi = sb[i] - Math.min.apply(Math, sb)
//           newA.push(ai);
//           newA.push(bi);
//           s += Math.max.apply(Math, newA);
//         }
//         console.log(s)
//         functions();
//       })
//     })
//   })
// })

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 t = +readLine();
  while (t--) {
    const arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    arr.sort((a, b) => a - b);
    const [x, y, z] = arr;

    if (y !== z) console.log("NO");
    else {
      console.log("YES");
      console.log(`${x} ${x} ${z}`);
    }
  }
}

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

let stdinInput = '';

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

process.stdin.on('end', () => {
  main(stdinInput);
});

function main(data) {
	data = data.split('\n');
	const testCases = data[0] * 1;
	let i = 1;
	while (i <= testCases) {
    let n = data[i].trim().split(' ');
    let x = n[0] * 1;
    let y = n[1] * 1;
    let z = n[2] * 1;
    let max = Math.max(x, y, z);
    let min = Math.min(x, y, z);
    if (x === y && x === z) {
      console.log('YES');
      console.log(x+' '+y+' '+z);
      i += 1;
      continue;
    }
    if ((x != max && y != max) || (x != max && z != max) || (y != max && z != max) || (x != y && y != z && x != z)) {
      console.log('NO');
      i += 1;
      continue;
    }
    if ((x == max && y == max) || (x == max && z == max) || (y == max && z == max)) {
      console.log('YES');
      console.log(max+' '+min+' '+min);
      i += 1;
      continue;
    }
    if (x === 1 || y === 1 || z === 1) {
      console.log('NO');
      i += 1;
      continue;
    }
	}
}

function solve() {
   var arr = readArray(Number);
   arr.sort(sortF);
   if (arr[1] !== arr[2]) {
      write('NO');
      return;
   }
   write('YES');
   write(arr.join(' '));
}

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 {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

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

      RL.on('close', 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();
}

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

rl.question("", function (n) {
  functions();
})

function functions() {
  rl.question('', function (input) {
    var n = input.split(' ');
    var l = []
    var x = n[0];
    var y = n[1];
    var z = n[2];
    var a, b, c, bool;
    bool = 'yes';
    if (x == y && y > z) {
      a = x;
      b = z;
      c = 1;
    } else if (x == z && z > y) {
      b = x;
      a = y;
      c = 1;
    } else if (y == z && z > x) {
      c = y;
      b = x;
      a = 1;
    } else if (x == y && y == z) {
      a = b = c = x;
    } else {
      bool = 'no';
    }
    if (bool == 'yes') {
      console.log(bool)
      console.log(a, b, c)
    } else {
      console.log(bool)
    }
    functions();
  })
}
// function functions() {
//   rl.question("", function (n) {
//     rl.question("", function (num) {
//       var arr = num.split(' ');
//       var l = [];
//       for (var i = 0; i < n * 2; i++) {
//         for (var j = 0; j < arr.length; j++) {
//           var lhas = l.includes(arr[j])
//           if (!lhas) {
//             l.push(arr[j]);
//
//           }
//         }
//       }
//       console.log(l.join(' '));
//       functions();
//     });
//   })
// }
// rl.question('', function (o) {
//   rl.question('', function (n) {
//     rl.question('', function (a) {
//       rl.question('', function (b) {
//         var s = 0;
//         var sa = a.split(' ');
//         var sb = b.split(' ');
//         // console.log(n, newA, s, sa, sb)
//         for (var i = 0; i < n; i++) {
//           var newA = [];
//           var ai = sa[i] - Math.min.apply(Math, sa)
//           var bi = sb[i] - Math.min.apply(Math, sb)
//           newA.push(ai);
//           newA.push(bi);
//           s += Math.max.apply(Math, newA);
//         }
//         console.log(s)
//         functions();
//       })
//     })
//   })
// })

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 t = +readLine();
  while (t--) {
    const [a, b, c] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    if (Math.max(a, b) === c) {
      console.log("YES");
      console.log(`${a} ${b} ${c}`);
    } else 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 t = +readLine();
  while (t--) {
    const [a, b, c] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    if (Math.max(a, b) === c) {
      console.log("YES");
      console.log(`${1} ${a} ${b}`);
    } else 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 t = +readLine();
  while (t--) {
    const [x, y, z] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    const [a, b, c] = [1, x, y];
    if (Math.max(a, b) === x && Math.max(a, c) === y && Math.max(b, c) === z) {
      console.log("YES");
      console.log(`${a} ${b} ${c}`);
    } else 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() {
  const arr = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  arr.sort((a, b) => a - b);
  const [x, y, z] = arr;

  if (y !== z) console.log("NO");
  else {
    console.log("YES");
    console.log(`${x} ${x} ${z}`);
  }
}

//↓見なくていいよ！ここから--------------------------------------------------
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 = new Date();
  Main();
  var end = new Date() - 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){
  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 myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
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;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = [];
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var x = one[0];
		var y = one[1];
		var z = one[2];
		if(x == z && x != y && y != z){
			if(y < x){
				output.push("YES");
				var a = x;
				output.push(y + " " + x + " " + y);
			}else{
				output.push("NO");
			}

		}else if(x == y && y == z && z == x){
			output.push("YES");
			output.push(x + " " + x + " " + x);
		}else if(x != y && x != z && y == z){
			if(x < y){
				output.push("YES");
				output.push(x + " " + y + " " + z);
			}else{
				output.push("NO");
			}
		}else if(x == y && x != z && y != z){
			if(x > z){
				output.push("YES");
				output.push(x + " " + z + " " + z);
			}else{
				output.push("NO");
			}
		}else{
			output.push("NO");
		}
	}
	myout(myconv(output,9));
}