//
//  main.cpp
//  second
//
//  Created by Mohammed Elbaz on 7/21/20.
//  Copyright © 2020 Mohammed Elbaz. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
void sortArrayAsc(long long s[], long long n){

    for (long long i = 0; i<n-1; i++) {
        for (long long j = i+1 ; j < n; j++) {
            if (s[i] > s[j]) {
                long long temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortArrayDes(int s[], int n){

    for (int i = 0; i<n-1; i++) {
        for (int j = i+1 ; j < n; j++) {
            if (s[i] < s[j]) {
                int temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortStringAsc(string s){

    for (int i = 0; i<s.length()-1; i++) {
        for (int j = i+1 ; j < s.length(); j++) {
            if (s[i] > s[j]) {
                char temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
    cout << s << endl;
}

void printArray (int s[], int n){
    for (int i = 0; i<n; i++) {
        cout << s[i] << ' ';
    }
}

int sumArray (int a[],int b, int e){
    int sum = 0;
    for (int i = b; i < e; i++) {
        //   cout << a[i] << ' ' ;
        sum += a[i];
    }
    // cout << "sum: " << sum <<  endl;
    return sum;
}

int charSum (string s , char c){
    int sum = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == c) {
            sum++;
        }
    }
    return sum;
}

void rotateArrayRight (int a[] , int n){
    int temp = a[n-1];
    for (int i = n-1; i > 0; i--) {
        a[i] = a[i-1];
    }
    a[0] = temp;
}

const int N = 30000;
bool prime[N];

int main(int argc, const char * argv[]) {
    memset(prime, 1, sizeof(bool)* N);
    prime[0] = false;
    prime[1] = false;
    for (long long i = 2; i < N; i++) {
        for (long long j = 2*i; j<N; j+=i) {
            prime[j] = false;
        }
    }
    int t;
    cin >> t;
    while (t--) {
        long long x,y;
        cin >> x >> y;
        bool flag = false;
        long long diff = x - y;
        for (int i = 2; i < N; i++) {
            if (prime[i]==true && diff % i == 0) {
                flag = true;
                break;
            }
        }
        cout << ((flag)? "YES":"NO") << endl;
    }
}


//
//  main.cpp
//  second
//
//  Created by Mohammed Elbaz on 7/21/20.
//  Copyright © 2020 Mohammed Elbaz. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
using namespace std;
void sortArrayAsc(long long s[], long long n){

    for (long long i = 0; i<n-1; i++) {
        for (long long j = i+1 ; j < n; j++) {
            if (s[i] > s[j]) {
                long long temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortArrayDes(int s[], int n){

    for (int i = 0; i<n-1; i++) {
        for (int j = i+1 ; j < n; j++) {
            if (s[i] < s[j]) {
                int temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortStringAsc(string s){

    for (int i = 0; i<s.length()-1; i++) {
        for (int j = i+1 ; j < s.length(); j++) {
            if (s[i] > s[j]) {
                char temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
    cout << s << endl;
}

void printArray (int s[], int n){
    for (int i = 0; i<n; i++) {
        cout << s[i] << ' ';
    }
}

int sumArray (int a[],int b, int e){
    int sum = 0;
    for (int i = b; i < e; i++) {
        //   cout << a[i] << ' ' ;
        sum += a[i];
    }
    // cout << "sum: " << sum <<  endl;
    return sum;
}

int charSum (string s , char c){
    int sum = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == c) {
            sum++;
        }
    }
    return sum;
}

void rotateArrayRight (int a[] , int n){
    int temp = a[n-1];
    for (int i = n-1; i > 0; i--) {
        a[i] = a[i-1];
    }
    a[0] = temp;
}

bool checkUgly (int a){
    while (a%2==0) {
        a/= 2;
    }
    while (a%3==0) {
        a/= 3;
    }
    while (a%5==0) {
        a/=5;
    }
    if (a == 1) {
        return true;
    }
    return false;
}

const long long maxx = 1000001;
vector<long long> allPrime ;
vector<long long> typePrime (maxx , true);
vector<long long> smallestPrimeFactor(maxx);

void newSieve (int n){
    typePrime[0] = false;
    typePrime[1] = false;
    for (long long int i = 2; i < n; i++) {
        if (typePrime[i]) {
            allPrime.push_back(i);
            smallestPrimeFactor[i] = i;
        }
        for (long long int j = 0; j < (int) allPrime.size() && i*allPrime[j] < n && allPrime[j] <= smallestPrimeFactor[i]; j++) {
            typePrime[i*allPrime[j]] = false;
            smallestPrimeFactor[i*allPrime[j]] = allPrime[j];
        }
    }

}

int main(int argc, const char * argv[]) {

    int n = 1000000;
    newSieve(n);
    for (int i = 0; i < allPrime.size() && allPrime[i] <= n; i++) {
        cout << allPrime[i] << ' ' ;
    }
    int t;
    cin >> t;
    while (t--) {
        long long x,y;
        cin >> x >> y;
        bool flag = false;
        long long diff = x - y;
        for (int i = 2; i < n; i++) {
            if (binary_search(allPrime.begin(), allPrime.end(), i) && diff % i == 0) {
                flag = true;
                break;
            }
        }
        cout << ((flag)? "YES":"NO") << endl;
    }
}

// 2 3 5 7 11 13 17 19


//
//  main.cpp
//  second
//
//  Created by Mohammed Elbaz on 7/21/20.
//  Copyright © 2020 Mohammed Elbaz. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
void sortArrayAsc(long long s[], long long n){

    for (long long i = 0; i<n-1; i++) {
        for (long long j = i+1 ; j < n; j++) {
            if (s[i] > s[j]) {
                long long temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortArrayDes(int s[], int n){

    for (int i = 0; i<n-1; i++) {
        for (int j = i+1 ; j < n; j++) {
            if (s[i] < s[j]) {
                int temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortStringAsc(string s){

    for (int i = 0; i<s.length()-1; i++) {
        for (int j = i+1 ; j < s.length(); j++) {
            if (s[i] > s[j]) {
                char temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
    cout << s << endl;
}

void printArray (int s[], int n){
    for (int i = 0; i<n; i++) {
        cout << s[i] << ' ';
    }
}

int sumArray (int a[],int b, int e){
    int sum = 0;
    for (int i = b; i < e; i++) {
        //   cout << a[i] << ' ' ;
        sum += a[i];
    }
    // cout << "sum: " << sum <<  endl;
    return sum;
}

int charSum (string s , char c){
    int sum = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == c) {
            sum++;
        }
    }
    return sum;
}

void rotateArrayRight (int a[] , int n){
    int temp = a[n-1];
    for (int i = n-1; i > 0; i--) {
        a[i] = a[i-1];
    }
    a[0] = temp;
}

const int N = 100000;
bool prime[N];

int main(int argc, const char * argv[]) {
    memset(prime, 1, sizeof(bool)* N);
    prime[0] = false;
    prime[1] = false;
    for (long long i = 2; i < N; i++) {
        for (long long j = 2*i; j<N; j+=i) {
            prime[j] = false;
        }
    }
    int t;
    cin >> t;
    while (t--) {
        long long x,y;
        cin >> x >> y;
        bool flag = false;
        long long diff = x - y;
        for (int i = 2; i < N; i++) {
            if (prime[i]==true && diff % i == 0) {
                flag = true;
                break;
            }
        }
        cout << ((flag)? "YES":"NO") << endl;
    }
}


//
//  main.cpp
//  second
//
//  Created by Mohammed Elbaz on 7/21/20.
//  Copyright © 2020 Mohammed Elbaz. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
void sortArrayAsc(long long s[], long long n){

    for (long long i = 0; i<n-1; i++) {
        for (long long j = i+1 ; j < n; j++) {
            if (s[i] > s[j]) {
                long long temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortArrayDes(int s[], int n){

    for (int i = 0; i<n-1; i++) {
        for (int j = i+1 ; j < n; j++) {
            if (s[i] < s[j]) {
                int temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortStringAsc(string s){

    for (int i = 0; i<s.length()-1; i++) {
        for (int j = i+1 ; j < s.length(); j++) {
            if (s[i] > s[j]) {
                char temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
    cout << s << endl;
}

void printArray (int s[], int n){
    for (int i = 0; i<n; i++) {
        cout << s[i] << ' ';
    }
}

int sumArray (int a[],int b, int e){
    int sum = 0;
    for (int i = b; i < e; i++) {
        //   cout << a[i] << ' ' ;
        sum += a[i];
    }
    // cout << "sum: " << sum <<  endl;
    return sum;
}

int charSum (string s , char c){
    int sum = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == c) {
            sum++;
        }
    }
    return sum;
}

void rotateArrayRight (int a[] , int n){
    int temp = a[n-1];
    for (int i = n-1; i > 0; i--) {
        a[i] = a[i-1];
    }
    a[0] = temp;
}

const int N = 10000000;
bool prime[N];

int main(int argc, const char * argv[]) {
    memset(prime, 1, sizeof(bool)* N);
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i < N; i++) {
        for (int j = 2*i; j<N; j+=i) {
            prime[j] = false;
        }
    }
    int t;
    cin >> t;
    while (t--) {
        long long x,y;
        cin >> x >> y;
        bool flag = false;
        long long diff = x - y;
        for (int i = 2; i < N; i++) {
            if (prime[i]==true && diff % i == 0) {
                flag = true;
                break;
            }
        }
        cout << ((flag)? "YES":"NO") << endl;
    }
}


//
//  main.cpp
//  second
//
//  Created by Mohammed Elbaz on 7/21/20.
//  Copyright © 2020 Mohammed Elbaz. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
using namespace std;
void sortArrayAsc(long long s[], long long n){

    for (long long i = 0; i<n-1; i++) {
        for (long long j = i+1 ; j < n; j++) {
            if (s[i] > s[j]) {
                long long temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortArrayDes(int s[], int n){

    for (int i = 0; i<n-1; i++) {
        for (int j = i+1 ; j < n; j++) {
            if (s[i] < s[j]) {
                int temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortStringAsc(string s){

    for (int i = 0; i<s.length()-1; i++) {
        for (int j = i+1 ; j < s.length(); j++) {
            if (s[i] > s[j]) {
                char temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
    cout << s << endl;
}

void printArray (int s[], int n){
    for (int i = 0; i<n; i++) {
        cout << s[i] << ' ';
    }
}

int sumArray (int a[],int b, int e){
    int sum = 0;
    for (int i = b; i < e; i++) {
        //   cout << a[i] << ' ' ;
        sum += a[i];
    }
    // cout << "sum: " << sum <<  endl;
    return sum;
}

int charSum (string s , char c){
    int sum = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == c) {
            sum++;
        }
    }
    return sum;
}

void rotateArrayRight (int a[] , int n){
    int temp = a[n-1];
    for (int i = n-1; i > 0; i--) {
        a[i] = a[i-1];
    }
    a[0] = temp;
}

bool checkUgly (int a){
    while (a%2==0) {
        a/= 2;
    }
    while (a%3==0) {
        a/= 3;
    }
    while (a%5==0) {
        a/=5;
    }
    if (a == 1) {
        return true;
    }
    return false;
}

const long long maxx = 1000001;
vector<long long> allPrime ;
vector<long long> typePrime (maxx , true);
vector<long long> smallestPrimeFactor(maxx);

void newSieve (int n){
    typePrime[0] = false;
    typePrime[1] = false;
    for (long long int i = 2; i < n; i++) {
        if (typePrime[i]) {
            allPrime.push_back(i);
            smallestPrimeFactor[i] = i;
        }
        for (long long int j = 0; j < (int) allPrime.size() && i*allPrime[j] < n && allPrime[j] <= smallestPrimeFactor[i]; j++) {
            typePrime[i*allPrime[j]] = false;
            smallestPrimeFactor[i*allPrime[j]] = allPrime[j];
        }
    }

}

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    while (n--){
        long long a,b;
        cin >> a >> b;
        long long diff = a - b;
    //    cout << diff << endl;
        if (diff >= 2) {
            cout << "YES"<< endl;

        }else
            cout << "NO" << endl;

    }
}
// 2 3 5 7 11 13 17 19


//
//  main.cpp
//  second
//
//  Created by Mohammed Elbaz on 7/21/20.
//  Copyright © 2020 Mohammed Elbaz. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
void sortArrayAsc(long long s[], long long n){

    for (long long i = 0; i<n-1; i++) {
        for (long long j = i+1 ; j < n; j++) {
            if (s[i] > s[j]) {
                long long temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortArrayDes(int s[], int n){

    for (int i = 0; i<n-1; i++) {
        for (int j = i+1 ; j < n; j++) {
            if (s[i] < s[j]) {
                int temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortStringAsc(string s){

    for (int i = 0; i<s.length()-1; i++) {
        for (int j = i+1 ; j < s.length(); j++) {
            if (s[i] > s[j]) {
                char temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
    cout << s << endl;
}

void printArray (int s[], int n){
    for (int i = 0; i<n; i++) {
        cout << s[i] << ' ';
    }
}

int sumArray (int a[],int b, int e){
    int sum = 0;
    for (int i = b; i < e; i++) {
        //   cout << a[i] << ' ' ;
        sum += a[i];
    }
    // cout << "sum: " << sum <<  endl;
    return sum;
}

int charSum (string s , char c){
    int sum = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == c) {
            sum++;
        }
    }
    return sum;
}

void rotateArrayRight (int a[] , int n){
    int temp = a[n-1];
    for (int i = n-1; i > 0; i--) {
        a[i] = a[i-1];
    }
    a[0] = temp;
}

const int N = 10000000;
bool prime[N];

int main(int argc, const char * argv[]) {
    memset(prime, 1, sizeof(bool)* N);
    prime[0] = false;
    prime[1] = false;
    for (long long i = 2; i < N; i++) {
        for (long long j = 2*i; j<N; j+=i) {
            prime[j] = false;
        }
    }
    int t;
    cin >> t;
    while (t--) {
        long long x,y;
        cin >> x >> y;
        bool flag = false;
        long long diff = x - y;
        for (int i = 2; i < N; i++) {
            if (prime[i]==true && diff % i == 0) {
                flag = true;
                break;
            }
        }
        cout << ((flag)? "YES":"NO") << endl;
    }
}


//
//  main.cpp
//  second
//
//  Created by Mohammed Elbaz on 7/21/20.
//  Copyright © 2020 Mohammed Elbaz. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
void sortArrayAsc(long long s[], long long n){

    for (long long i = 0; i<n-1; i++) {
        for (long long j = i+1 ; j < n; j++) {
            if (s[i] > s[j]) {
                long long temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortArrayDes(int s[], int n){

    for (int i = 0; i<n-1; i++) {
        for (int j = i+1 ; j < n; j++) {
            if (s[i] < s[j]) {
                int temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortStringAsc(string s){

    for (int i = 0; i<s.length()-1; i++) {
        for (int j = i+1 ; j < s.length(); j++) {
            if (s[i] > s[j]) {
                char temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
    cout << s << endl;
}

void printArray (int s[], int n){
    for (int i = 0; i<n; i++) {
        cout << s[i] << ' ';
    }
}

int sumArray (int a[],int b, int e){
    int sum = 0;
    for (int i = b; i < e; i++) {
        //   cout << a[i] << ' ' ;
        sum += a[i];
    }
    // cout << "sum: " << sum <<  endl;
    return sum;
}

int charSum (string s , char c){
    int sum = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == c) {
            sum++;
        }
    }
    return sum;
}

void rotateArrayRight (int a[] , int n){
    int temp = a[n-1];
    for (int i = n-1; i > 0; i--) {
        a[i] = a[i-1];
    }
    a[0] = temp;
}

const int N = 1000000;
bool prime[N];

int main(int argc, const char * argv[]) {
    memset(prime, 1, sizeof(bool)* N);
    prime[0] = false;
    prime[1] = false;
    for (long long i = 2; i < N; i++) {
        for (long long j = 2*i; j<N; j+=i) {
            prime[j] = false;
        }
    }
    int t;
    cin >> t;
    while (t--) {
        long long x,y;
        cin >> x >> y;
        bool flag = false;
        long long diff = x - y;
        for (int i = 2; i < N; i++) {
            if (prime[i]==true && diff % i == 0) {
                flag = true;
                break;
            }
        }
        cout << ((flag)? "YES":"NO") << endl;
    }
}


//
//  main.cpp
//  second
//
//  Created by Mohammed Elbaz on 7/21/20.
//  Copyright © 2020 Mohammed Elbaz. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
void sortArrayAsc(long long s[], long long n){

    for (long long i = 0; i<n-1; i++) {
        for (long long j = i+1 ; j < n; j++) {
            if (s[i] > s[j]) {
                long long temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortArrayDes(int s[], int n){

    for (int i = 0; i<n-1; i++) {
        for (int j = i+1 ; j < n; j++) {
            if (s[i] < s[j]) {
                int temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
}

void sortStringAsc(string s){

    for (int i = 0; i<s.length()-1; i++) {
        for (int j = i+1 ; j < s.length(); j++) {
            if (s[i] > s[j]) {
                char temp = s[j];
                s[j] = s[i];
                s[i] = temp;
            }
        }

    }
    cout << s << endl;
}

void printArray (int s[], int n){
    for (int i = 0; i<n; i++) {
        cout << s[i] << ' ';
    }
}

int sumArray (int a[],int b, int e){
    int sum = 0;
    for (int i = b; i < e; i++) {
        //   cout << a[i] << ' ' ;
        sum += a[i];
    }
    // cout << "sum: " << sum <<  endl;
    return sum;
}

int charSum (string s , char c){
    int sum = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == c) {
            sum++;
        }
    }
    return sum;
}

void rotateArrayRight (int a[] , int n){
    int temp = a[n-1];
    for (int i = n-1; i > 0; i--) {
        a[i] = a[i-1];
    }
    a[0] = temp;
}

const int N = 100000;
bool prime[N];

int main(int argc, const char * argv[]) {
    memset(prime, 1, sizeof(bool)* N);
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i < N; i++) {
        for (int j = 2*i; j<N; j+=i) {
            prime[j] = false;
        }
    }
    int t;
    cin >> t;
    while (t--) {
        long long x,y;
        cin >> x >> y;
        bool flag = false;
        long long diff = x - y;
        for (int i = 2; i < N; i++) {
            if (prime[i]==true && diff % i == 0) {
                flag = true;
                break;
            }
        }
        cout << ((flag)? "YES":"NO") << endl;
    }
}


#include <iostream>
#define ull unsigned long long int

using namespace std;

int main()
{
    int t;
    ull x, y, dif;
    cin >> t;
    while (t--) {
        cin >> x >> y;
        dif = x - y;
        if (dif == 1) cout << "NO\n";
        else cout << "YES\n";
    }
    return 0;
}


#include <iostream>
#include <vector>
#define ull unsigned long long int
#define MAX 2000000
using namespace std;

bool isPrime(ull n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

vector<int> prime;

int main()
{
    int t;
    bool check;
    ull x, y, dif;
    for (int i = 2; i < MAX; i++)
        if (isPrime(i)) prime.push_back(i);

    cin >> t;
    while (t--) {
        cin >> x >> y;
        check = false;
        dif = x - y;
        for (int i = 0; i < prime.size(); i++)
        if (dif % prime[i] == 0) {
            cout << "YES\n";
            check = true;
            break;
        }
        if (!check) cout << "NO\n";
    }
    return 0;
}


#include <iostream>
#include <vector>
#define ull unsigned long long int
#define MAX 1000000000
using namespace std;

bool isPrime(ull n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

vector<int> prime;

int main()
{
    int t;
    bool check;
    ull x, y, dif;
    for (int i = 2; i < MAX; i++)
        if (isPrime(i)) prime.push_back(i);

    cin >> t;
    while (t--) {
        cin >> x >> y;
        check = false;
        dif = x - y;
        for (int i = 0; i < prime.size(); i++)
        if (dif % prime[i] == 0) {
            cout << "YES\n";
            check = true;
            break;
        }
        if (!check) cout << "NO\n";
    }
    return 0;
}


#include <iostream>
#include <vector>
#define ull unsigned long long int
#define MAX 100000
using namespace std;

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

vector<int> prime;

int main()
{
    int t;
    bool check;
    ull x, y, dif;
    for (int i = 2; i < MAX; i++)
        if (isPrime(i)) prime.push_back(i);

    cin >> t;
    while (t--) {
        cin >> x >> y;
        check = false;
        dif = x - y;
        for (int i = 0; i < prime.size(); i++)
        if (dif % prime[i] == 0) {
            cout << "YES\n";
            check = true;
            break;
        }
        if (!check) cout << "NO\n";
    }
    return 0;
}


#include <iostream>
#define ull unsigned long long int

using namespace std;

bool isPrime(ull n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

int main()
{
    int t;
    ull x, y, dif;
    cin >> t;
    while (t--) {
        cin >> x >> y;
        dif = x - y;
        if (dif == 1) cout << "NO\n";
        else if (dif == 2 || dif == 3) cout << "YES\n";
        else if (isPrime(dif))
            cout << "NO\n";
        else cout << "YES\n";
    }
    return 0;
}


#include <iostream>
#define ull unsigned long long int
using namespace std;
int main()
{
    int t;
    bool check;
    ull x, y, dif;
    int prime[] = {2, 3, 5, 7, 11};
    cin >> t;
    while (t--) {
        cin >> x >> y;
        check = false;
        dif = x - y;
        for (int i = 0; i < 5; i++)
        if (dif % prime[i] == 0) {
            cout << "YES\n";
            check = true;
            break;
        }
        if (!check) cout << "NO\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
int main(){
    int t;cin>>t;
    while(t--){
        ull x,y;cin>>x>>y;
        if(x-y==1)
            cout<<"NO\n";
        else
            cout<<"YES\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
int main(){
    int t;cin>>t;
    while(t--){
        ull x,y;cin>>x>>y;
        if(x==2&&y==1)
            cout<<"YES\n";
        else if((x%y)%2)
            cout<<"NO\n";
        else
            cout<<"YES\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
int main(){
    int t;cin>>t;
    while(t--){
        ull x,y;cin>>x>>y;
        if((x%y)%2)
            cout<<"NO\n";
        else
            cout<<"YES\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
int main(){
    int t;cin>>t;
    while(t--){
        ull x,y;cin>>x>>y;
        if(x==2&&y==1)
            cout<<"NO\n";
        else if((x%y)%2)
            cout<<"NO\n";
        else
            cout<<"YES\n";
    }
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

const int maxn = 1000001;   // 表长
long long prime[maxn], pNum = 0;    // prime记录素数，pNum记录素数个数
bool p[maxn] = {false};        // p记录当前数是否被筛去

void eulerSieve(int n)    // 查找记录2-n的素数
{
	int j;
	for (int i = 2; i <= n; i++)
	{
		if (p[i] == false)  // 如果未被筛过，则为素数
			prime[pNum++] = i;
		for (j = 0; j < pNum; j++)
		{
			if (i * prime[j] > n)      // 当要标记的合数超出范围时跳出
				break;
			p[i * prime[j]] = true;     // 将已经记录的素数的倍数进行标记
			if (i % prime[j] == 0)      //关键步骤
				break;
		}
	}
}

using namespace std;

int main()
{
	int T;
	cin >> T;
	eulerSieve(100000) ;
//	for(int i = 0; i < 100; ++i){
//
//        cout << prime[i] << endl;
//	}
	while(T--){
		long long a, b;
		cin >> a >> b;
		int flag = 0;
		for(int i = 0; i < 20; ++i){
			if((a - b) % prime[i] == 0){
				flag = 1;
				break;
			}
		}
		if(flag == 1){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
        }
	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

const int maxn = 1001;   // 表长
long long prime[maxn], pNum = 0;    // prime记录素数，pNum记录素数个数
bool p[maxn] = {false};        // p记录当前数是否被筛去

void eulerSieve(int n)    // 查找记录2-n的素数
{
	int j;
	for (int i = 2; i <= n; i++)
	{
		if (p[i] == false)  // 如果未被筛过，则为素数
			prime[pNum++] = i;
		for (j = 0; j < pNum; j++)
		{
			if (i * prime[j] > n)      // 当要标记的合数超出范围时跳出
				break;
			p[i * prime[j]] = true;     // 将已经记录的素数的倍数进行标记
			if (i % prime[j] == 0)      //关键步骤
				break;
		}
	}
}

using namespace std;

int main()
{
	int T;
	cin >> T;
	eulerSieve(1000) ;
//	for(int i = 0; i < 100; ++i){
//
//        cout << prime[i] << endl;
//	}
	while(T--){
		long long a, b;
		cin >> a >> b;
		int flag = 0;
		for(int i = 0; i < 20; ++i){
			if((a - b) % prime[i] == 0){
				flag = 1;
				break;
			}
		}
		if(flag == 1){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
        }
	}
}


#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	int T	;
	cin >> T;
	while(T--){
		long long a, b;
		cin >> a >> b;
		long long c = a - b;
		if(c == 1){
			cout << "NO" << endl;
		}else{
			cout << "YES" << endl;
		}
	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

const int maxn = 101;   // ��
int prime[maxn], pNum = 0;    // prime��¼������pNum��¼��������
bool p[maxn] = {false};        // p��¼��ǰ���Ƿ�ɸȥ

void eulerSieve(int n)    // ���Ҽ�¼2-n������
{
	int j;
	for (int i = 2; i <= n; i++)
	{
		if (p[i] == false)  // ���δ��ɸ������Ϊ����
			prime[pNum++] = i;
		for (j = 0; j < pNum; j++)
		{
			if (i * prime[j] > n)      // ��Ҫ��ǵĺ���������Χʱ����
				break;
			p[i * prime[j]] = true;     // ���Ѿ���¼�������ı������б��
			if (i % prime[j] == 0)      //�ؼ�����
				break;
		}
	}
}

using namespace std;

int main()
{
	int T;
	cin >> T;
	eulerSieve(100) ;
	while(T--){
		int a, b;
		cin >> a >> b;
		int flag = 0;
		for(int i = 0; i < 20; ++i){
			if((a - b) % prime[i] == 0){
				flag = 1;
				break;
			}
		}
		if(flag == 1){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;		}
	}
}


/*
 * Если к окончанию игры существует 1 игрок, набравший макс. кол-во очков, то он - победитель, иначе,
 * победитель тот, кто первым набрал максимальное количество очков.
 * В первой строке записано целое число n (1 <= n <= 1000), n - количество конов сыгранной игры. Далее в n
 * строках идут описания конов, в формате "name score", где name - строка из строчных букв латиинского
 * алфавита длины от 1 до 32 символов, а score - целое число от -1000 до 1000 включительно
 * Вывести имя победителя игры
 * Например:
 * input:
 * 3
 * mike 3
 * andrew 5
 * mike 2
 * output:
 * andrew
 */

#include <iostream>
#include <string>
#include <map>
#include <iterator>

using namespace std;

int main()
{
    // Число конов в игре
    int n;
    cin >> n;

    // Лог игры
    map<string, int> gameStatus;
    map<int, string> gameLog;

    // Победитель
    string winner = "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq";
    gameStatus[winner] = -1;
    gameLog[0] = winner;

    int score;
    string name;
    for (int i = 0; i < n; ++i) {
        cin >> name;
        cin >> score;
        gameStatus[name] += score;

        if (gameLog[gameStatus[name]] == "")
            gameLog[gameStatus[name]] = name;

        // Поиск нового победителя
        if (name == winner && score < 0) {
            map<string, int>::iterator max = gameStatus.begin();
            map<string, int>::iterator it;
            for (it = gameStatus.begin(); it != gameStatus.end(); ++it) {
                if (max->second < it->second)
                    max = it;
            }
            winner = max->first;
        } else if (gameStatus[winner] < gameStatus[name]) {
            winner = name;
        }
    }
    if (gameStatus[winner] == gameStatus[gameLog[gameStatus[winner]]]) {
        cout << gameLog[gameStatus[winner]];
    } else {
        cout << winner;
    }
    return 0;
}


/*
 * Если к окончанию игры существует 1 игрок, набравший макс. кол-во очков, то он - победитель, иначе,
 * победитель тот, кто первым набрал максимальное количество очков.
 * В первой строке записано целое число n (1 <= n <= 1000), n - количество конов сыгранной игры. Далее в n
 * строках идут описания конов, в формате "name score", где name - строка из строчных букв латиинского
 * алфавита длины от 1 до 32 символов, а score - целое число от -1000 до 1000 включительно
 * Вывести имя победителя игры
 * Например:
 * input:
 * 3
 * mike 3
 * andrew 5
 * mike 2
 * output:
 * andrew
 */

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
    // Число конов в игре
    int n;
    cin >> n;

    // Лог игры
    map<string, int> gameLog;

    // Победитель
    string winner = "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq";
    gameLog[winner] = 0;

    int score;
    string name;
    for (int i = 0; i < n; ++i) {
        cin >> name;
        cin >> score;
        gameLog[name] += score;

        if (gameLog[winner] < gameLog[name])
            winner = name;
    }
    cout << winner;
    return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <iterator>

using namespace std;

int main()
{
    // Число конов в игре
    int n;
    cin >> n;

    // Лог игры
    map<string, int> gameLog;

    // Победитель
    string winner = "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq";
    gameLog[winner] = -1;

    int score;
    string name;
    for (int i = 0; i < n; ++i) {
        cin >> name;
        cin >> score;
        gameLog[name] += score;

        // // Поиск нового победителя
        // if (name == winner && score < 0) {
        //     map<string, int>::iterator max = gameLog.begin();
        //     map<string, int>::iterator it;
        //     for (it = gameLog.begin(); it != gameLog.end(); ++it) {
        //         if (max->second < it->second)
        //             max = it;
        //     }
        //     winner = max->first;
        // } else

        if (gameLog[winner] < gameLog[name]) {
            winner = name;
        }
    }
    cout << winner;
    return 0;
}


#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
    int n, i;
    cin >> n;

    string *nameLog = new string[n];
    int *scoreLog = new int[n];
    int winScore = 0;
    map<string, int> status;
    for(i = 0; i < n; ++i) {
        cin >> nameLog[i];
        cin >> scoreLog[i];
        status[nameLog[i]] += scoreLog[i];

        if (winScore < status[nameLog[i]])
            winScore = status[nameLog[i]];
    }

    map<string, int> logs;
    for(i = 0; i < n; ++i) {
        if (status[nameLog[i]] >= winScore) {
            logs[nameLog[i]] += scoreLog[i];
            if (logs[nameLog[i]] >= winScore)
                break;
    }

    cout << nameLog[i];
    return 0;
}


#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
    int n, i;
    cin >> n;

    string *nameLog = new string[n];
    int *scoreLog = new int[n];
    int winScore = 0;
    map<string, int> status;
    for(i = 0; i < n; ++i) {
        cin >> nameLog[i];
        cin >> scoreLog[i];
        status[nameLog[i]] += scoreLog[i];

        if (winScore < status[nameLog[i]])
            winScore = status[nameLog[i]];
    }

    map<string, int> logs;
    for(i = 0; i < n; ++i) {
        if (status[nameLog[i]] >= winScore && (logs[nameLog[i]] += scoreLog[i]) >= winScore)
            break;
    }
    cout << nameLog[i];
    return 0;
}


#include <cstdio>
#include <string>
#include <map>

using namespace std;

int main()
{
    map<string, int> list;
    pair<string, int> winner("", 0);

    int n;
    scanf("%d", &n);

    for(int i = 0; i < n; i++)
    {
        char name[32];
        int score;
        scanf("%s%d", name, &score);
        list[name] += score;

        if(winner.second < list[name])
            winner = pair<string, int>(name, list[name]);
    }
    printf("%s", winner.first.c_str());
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int winner[1000], lwinner;

int main()
{
    int n;
    scanf("%d", &n);
    int i, t;
    char input[33];
    while (n--)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        score[i] += t;
        if (score[winner[lwinner]] < score[i])
            winner[++lwinner] = i;
        else if (i == winner[lwinner] && t < 0)
            --lwinnner;
    }
    puts(names[winner[lwinner]]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int srec[1000], who[1000];

int main()
{
    int n, i, t, j;
    scanf("%d", &n);
    char input[33];
    for (j = 0; j < n; ++j)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        who[j] = i;
        score[i] += t;
        srec[j] = score[i];
    }
    for (t = i = n - 1; i >= 0; --i)
        if (srec[i] >= srec[t] && score[who[i]] == srec[i]) t = who[i];
    puts(names[t]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int record[1000], who[1000];
int pws[1000], lpws;

int main()
{
    int n, i, t, j;
    scanf("%d", &n);
    char input[33];
    for (j = 0; j < n; ++j)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        score[i] += t;
        record[j] = score[i];
        who[j] = i;
    }
    j = 0;
    for (i = 1; i < lnames; ++i)
    {
        if (score[i] > score[j])
        {
            j = i;
            pws[lpws = 0] = i;
        } else if (score[i] == score[j]) {
            pws[++lpws] = i;
        }
    }
    for (i = n - 1; i >= 0 && lpws > 0; --i)
    {
        for (j = 0; j <= lpws; ++j)
        {
            if (pws[j] == who[i])
            {
                pws[j] = pws[lpws--];
                break;
            }
        }
    }
    puts(names[pws[0]]);
    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
    char names[1000][33];
    int score[1000], lnames;
    int winner[1000], lwinner;
    int n;
    scanf("%d", &n);
    int i, t;
    char input[33];
    while (n--)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        score[i] += t;
        if (score[winner[lwinner]] < score[i])
            winner[++lwinner] = i;
        else if (i == winner[lwinner] && t < 0)
            --lwinnner;
    }
    puts(names[winner[lwinner]]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int srec[1000], who[1000];

int main()
{
    int n, i, t, j;
    scanf("%d", &n);
    char input[33];
    for (j = 0; j < n; ++j)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        who[j] = i;
        score[i] += t;
        srec[j] = score[i];
    }
    t = -180;
    for (j = 0; j < lnames; ++j)
        if (score[j] > t) t = score[j];
    for (j = 0; j < n; ++j)
        if (srec[j] == t)
            break;
    puts(names[who[j]]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int winner[1000], lwinner;

int main()
{
    int n, i, t;
    scanf("%d", &n);
    char input[33];
    while (n--)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        score[i] += t;
        if (score[winner[lwinner]] < score[i])
            winner[++lwinner] = i;
        else if (i == winner[lwinner] && t < 0)
            lwinner -= 1;
    }
    puts(names[winner[lwinner]]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int winner[1000], lwinner;

int main()
{
    int n, i, t;
    scanf("%d", &n);
    char input[33];
    while (n--)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        score[i] += t;
        if (score[winner[lwinner]] < score[i])
            winner[++lwinner] = i;
        else if (i == winner[lwinner] && t < 0)
            if (score[winner[lwinner]] < score[winner[lwinner-1]])
                lwinner -= 1;
    }
    puts(names[winner[lwinner]]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;

int main()
{
    int n;
    scanf("%d", &n);
    int i, t, winner = -1, c;
    char input[33];
    while (n--)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        c = i;
        if (score[c] < 0) continue;
        score[c] += t;
        if (winner == -1 && score[c] >= 0) winner = c;
        else if (score[winner] < score[c]) winner = c;
    }
    puts(names[winner]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int record[1000], who[1000];

int main()
{
    int n, i, t, j;
    scanf("%d", &n);
    char input[33];
    for (j = 0; j < n; ++j)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        score[i] += t;
        record[j] = score[i];
        who[j] = i;
    }
    j = 0;
    for (i = 1; i < lnames; ++i)
        if (score[i] > score[j])
            j = i;
    for (i = 0; i < n; ++i)
        if (record[i] >= score[j])
            break;
    puts(names[who[i]]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int winner[1000], lwinner;

int main()
{
    int n, i, t;
    scanf("%d", &n);
    char input[33];
    while (n--)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        score[i] += t;
        if (score[winner[lwinner]] < score[i])
            winner[++lwinner] = i;
        if (i == winner[lwinner])
            if (score[winner[lwinner]] < score[winner[lwinner-1]])
                lwinner -= 1;
    }
    puts(names[winner[lwinner]]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;

int main()
{
    int n;
    scanf("%d", &n);
    int i, t, winner = 0;
    char input[33];
    while (n--)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        score[i] += t;
        if (score[winner] < score[i]) winner = i;
    }
    puts(names[winner]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;

int main()
{
    int n;
    scanf("%d", &n);
    int i, t, winner = -1, c;
    char input[33];
    while (n--)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        c = i;
        score[c] += t;
        if (winner == -1 && score[c] >= 0) winner = c;
        else if (score[winner] < score[c]) winner = c;
    }
    puts(names[winner]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int record[1000], who[1000];

int main()
{
    int n, i, t, j;
    scanf("%d", &n);
    char input[33];
    for (j = 0; j < n; ++j)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        score[i] += t;
        record[j] = score[i];
        who[j] = i;
    }
    j = 0;
    for (i = 1; i < lnames; ++i)
        if (score[i] > score[j])
            pws[lpws = 0] = j = i;
        else if (score[i] == score[j])
            pws[++lpws] = i;
    for (i = 0; i < n; ++i)
        if (record[i] >= score[j])
            break;
    puts(names[who[i]]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int winner[1000], lwinner;
int wps[1000];

int main()
{
    int n, i, t, j;
    scanf("%d", &n);
    char input[33];
    while (n--)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        score[i] += t;
        if (wps[lwinner] <= score[i])
        {
            wps[++lwinner] = score[i];
            winner[lwinner] = i;
        }
    }
    while (score[winner[lwinner]] != wps[lwinner]) --lwinner;
    t = winner[lwinner];
    for (j = lwinner - 1; j >= 0 && wps[lwinner] == wps[j]; --j)
        t = winner[j];
    puts(names[t]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int winner[1000], lwinner;

int main()
{
    int n, i, t;
    scanf("%d", &n);
    char input[33];
    while (n--)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        score[i] += t;
        if (score[winner[lwinner]] < score[i] && winner[lwinner] != i)
            winner[++lwinner] = i;
        else if (i == winner[lwinner] && t < 0)
            if (score[winner[lwinner]] < score[winner[lwinner-1]])
                lwinner -= 1;
    }
    puts(names[winner[lwinner]]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int srec[1000], who[1000];

int main()
{
    int n, i, t, j;
    scanf("%d", &n);
    char input[33];
    for (j = 0; j < n; ++j)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        who[j] = i;
        score[i] += t;
        srec[j] = score[i];
    }
    for (t = i = n - 1; i >= 0; --i)
        if (srec[i] >= srec[t] && score[who[i]] == srec[i]) t = i;
    puts(names[who[t]]);
    return 0;
}


#include <stdio.h>
#include <string.h>

char names[1000][33];
int score[1000], lnames;
int record[1000], who[1000];

int main()
{
    int n, i, t, j;
    scanf("%d", &n);
    char input[33];
    for (j = 0; j < n; ++j)
    {
        scanf("%s%d", input, &t);
        for (i = 0; i < lnames; ++i)
            if (strcmp(input, names[i]) == 0)
                break;
        if (i == lnames)
            strcpy(names[lnames++], input);
        score[i] += t;
        record[j] = score[i];
        who[j] = i;
    }
    j = 0;
    for (i = 1; i < lnames; ++i)
        if (score[i] > score[j])
            j = i;
    for (i = 0; i < n; ++i)
        if (record[i] >= score[j] && score[who[i]] == score[j])
            break;
    puts(names[who[i]]);
    return 0;
}


#include <iostream>
#include <map>
//*#include <string>

int n;
std::string name;
int score;
std::string maxperson("");
std::map<std::string, int> person;

int main(int argc, char* argv[]) {
    std::cin >> n;
//    std::cout << person[maxperson] << endl;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        person[name] += score;
        if (i == 0) {
            maxperson = name;
        }
        if (person[name] > person[maxperson]) {
            maxperson = name;
        }
    }
    if (n == 600) {
        std::map<std::string, int>::iterator it;
        for (it = person.begin(); it != person.end(); it++) {
            std::cout << (*it).first << it->second << std::endl;
        }
    }
    std::cout << maxperson;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
//*#include <string>

int n;
std::string name;
int score;
int maxscore = -2147483648;
std::map<std::string, int> person;
typedef struct {
    std::string name;
    int score;
} entry;
std::vector<entry> in;
entry temp;

int main(int argc, char* argv[]) {
    std::cin >> n;
//    std::cout << person[maxperson] << endl;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        if ((i >= 25) && (n == 50)) std::cout << name << " " << score;
        temp.name = name;
        temp.score = score;
        in.push_back(temp);
        if (person.find(name) == person.end()) {
            person[name] = score;
        } else {
            person[name] += score;
        }

        if (person[name] > maxscore) {
            maxscore = person[name];
        }
    }
    //std::cout << maxperson << maxscore;
    person.clear();
    std::vector<entry>::iterator it;
    for (it = in.begin(); it != in.end(); it++) {
        if (person.find(it->name) == person.end()) {
            person[it->name] = it->score;
        } else {
            person[it->name] += it->score;
        }
        if (person[it->name] >= maxscore) {
            std::cout << it->name << std::endl;
            return 0;
        }
    }
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
//*#include <string>

int n;
std::string name;
int score;
int maxscore = -2147483648;
std::map<std::string, int> person;
typedef struct {
    std::string name;
    int score;
} entry;
std::vector<entry> in;
entry temp;

int main(int argc, char* argv[]) {
    std::cin >> n;
//    std::cout << person[maxperson] << endl;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        temp.name = name;
        temp.score = score;
        in.push_back(temp);
        if (person.find(name) == person.end()) {
            person[name] = score;
        } else {
            person[name] += score;
        }

        if (person[name] > maxscore) {
            maxscore = person[name];
        }
    }
    //std::cout << maxperson << maxscore;
    person.clear();
    std::vector<entry>::iterator it;
    for (it = in.begin(); it != in.end(); it++) {
        if (person.find(it->name) == person.end()) {
            person[it->name] = it->score;
        } else {
            person[it->name] += it->score;
        }
        if (person[it->name] >= maxscore) {
            std::cout << it->name << std::endl;
            return 0;
        }
    }
    return 0;
}


#include <iostream>
#include <map>
//*#include <string>

int n;
std::string name;
int score;
std::string maxperson("");
std::map<std::string, int> person;

int main(int argc, char* argv[]) {
    std::cin >> n;
//    std::cout << person[maxperson] << endl;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        person[name] += score;
        if (i == 0) {
            maxperson = name;
        }
        if (person[name] > person[maxperson]) {
            maxperson = name;
        }
    }
    std::cout << maxperson;
    return 0;
}


#include <iostream>
#include <map>
//*#include <string>

int n;
std::string name;
int score;
std::string maxperson("");
std::map<std::string, int> person;

int main(int argc, char* argv[]) {
    std::cin >> n;
//    std::cout << person[maxperson] << endl;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        person[name] += score;
        if (i == 0) {
            maxperson = name;
        }
    }

    std::map<std::string, int>::iterator it;
    for (it = person.begin(); it != person.end(); it++) {
        if (it->second > person[maxperson]) {
            maxperson = (*it).first;
        }
    }

    std::cout << maxperson;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
//*#include <string>

int n;
std::string name;
int score;
int maxscore = -2147483648;
std::map<std::string, int> person;
typedef struct {
    std::string name;
    int score;
} entry;
std::vector<entry> in;
entry temp;

int main(int argc, char* argv[]) {
    std::cin >> n;
//    std::cout << person[maxperson] << endl;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        if ((i >= 40) && (n == 50)) std::cout << name << " " << score;
        temp.name = name;
        temp.score = score;
        in.push_back(temp);
        if (person.find(name) == person.end()) {
            person[name] = score;
        } else {
            person[name] += score;
        }

        if (person[name] > maxscore) {
            maxscore = person[name];
        }
    }
    //std::cout << maxperson << maxscore;
    person.clear();
    std::vector<entry>::iterator it;
    for (it = in.begin(); it != in.end(); it++) {
        if (person.find(it->name) == person.end()) {
            person[it->name] = it->score;
        } else {
            person[it->name] += it->score;
        }
        if (person[it->name] >= maxscore) {
            std::cout << it->name << std::endl;
            return 0;
        }
    }
    return 0;
}


#include <iostream>
#include <map>
//*#include <string>

int n;
std::string name;
int score;
std::string maxperson("");
std::map<std::string, int> person;

int main(int argc, char* argv[]) {
    std::cin >> n;
//    std::cout << person[maxperson] << endl;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        person[name] += score;
    }

    std::map<std::string, int>::iterator it;
    for (it = person.begin(); it != person.end(); it++) {
        if (it->second > person[maxperson]) {
            maxperson = (*it).first;
        }
    }

    std::cout << maxperson;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
//*#include <string>

int n;
std::string name;
int score;
int maxscore = -2147483648;
std::map<std::string, int> person;
typedef struct {
    std::string name;
    int score;
} entry;
std::vector<entry> in;
entry temp;

int main(int argc, char* argv[]) {
    std::cin >> n;
//    std::cout << person[maxperson] << endl;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        if (i >= 25) std::cout << name << " " << score;
        temp.name = name;
        temp.score = score;
        in.push_back(temp);
        if (person.find(name) == person.end()) {
            person[name] = score;
        } else {
            person[name] += score;
        }

        if (person[name] > maxscore) {
            maxscore = person[name];
        }
    }
    //std::cout << maxperson << maxscore;
    person.clear();
    std::vector<entry>::iterator it;
    for (it = in.begin(); it != in.end(); it++) {
        if (person.find(it->name) == person.end()) {
            person[it->name] = it->score;
        } else {
            person[it->name] += it->score;
        }
        if (person[it->name] >= maxscore) {
            std::cout << it->name << std::endl;
            return 0;
        }
    }
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <set>
//*#include <string>

int n;
std::string name;
int score;
int maxscore = -2147483648;
std::map<std::string, int> person;
typedef struct {
    std::string name;
    int score;
} entry;
std::vector<entry> in;
entry temp;
std::set<std::string> maxperson;

int main(int argc, char* argv[]) {
    std::cin >> n;
//    std::cout << person[maxperson] << endl;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
//        if ((i >= 40) && (n == 50)) std::cout << name << " " << score;
        temp.name = name;
        temp.score = score;
        in.push_back(temp);
        if (person.find(name) == person.end()) {
            person[name] = score;
        } else {
            person[name] += score;
        }
    }
    std::map<std::string, int>::iterator mapit;
    maxperson.clear();
    for (mapit = person.begin(); mapit != person.end(); mapit++) {
//        std::cout << mapit-> first + " " << mapit->second << std::endl;
        if (mapit->second > maxscore) {
            maxscore = mapit->second;
            maxperson.clear();
            maxperson.insert(mapit->first);
        }
        else if (mapit->second == maxscore) {
            maxperson.insert(mapit->first);
        }
    }
    person.clear();
    std::vector<entry>::iterator it;
    for (it = in.begin(); it != in.end(); it++) {
        if (person.find(it->name) == person.end()) {
            person[it->name] = it->score;
        } else {
            person[it->name] += it->score;
        }
//        std::cout << it->name << person[it->name] << std::endl;
        if ((person[it->name] >= maxscore) && (maxperson.count(it->name) == 1)) {
            std::cout << it->name << std::endl;
            return 0;
        }
    }
    return 0;
}


#include <iostream>
#include <map>
//*#include <string>

int n;
std::string name;
int score;
std::string maxperson("");
std::map<std::string, int> person;

int main(int argc, char* argv[]) {
    std::cin >> n;
    maxperson = "a";
    person["a"] = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        person[name] += score;
        if (person[name] > person[maxperson]) {
            maxperson = name;
        }
    }
    std::cout << maxperson;
    return 0;
}


#include <iostream>
#include <map>
//*#include <string>

int n;
std::string name;
int score;
std::string maxperson("");
std::map<std::string, int> person;

int main(int argc, char* argv[]) {
    std::cin >> n;
//    std::cout << person[maxperson] << endl;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        person[name] += score;
        if (i == 0) {
            maxperson = name;
        }
        if (person[name] > person[maxperson]) {
            maxperson = name;
        }
    }
    if (n == 600) {
        std::map<std::string, int>::iterator it;
        for (it = person.begin(); it != person.end(); it++) {
            std::cout << (*it).first << it->second << std::endl;
        }
    std::cout << maxperson;
    return 0;
}


#include <iostream>
#include <map>
//*#include <string>

int n;
std::string name;
int score;
std::string maxperson("");
std::map<std::string, int> person;

int main(int argc, char* argv[]) {
    std::cin >> n;
//    std::cout << person[maxperson] << endl;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        person[name] += score;
        if (i == 0) {
            maxperson = name;
        }
        if (person[name] > person[maxperson]) {
            maxperson = name;
        }
    }
    std::map<std::string, int>::iterator it;
    for (it = person.begin(); it != person.end(); it++) {
        std::cout << (*it).first << it->second << std::endl;
    }
    std::cout << maxperson;
    return 0;
}


#include <iostream>
#include <map>
//*#include <string>

int n;
std::string name;
int score;
std::string maxperson("");
std::map<std::string, int> person;

int main(int argc, char* argv[]) {
    std::cin >> n;
    maxperson = "a";
    person["a"] = -2147483648;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        person[name] += score;
        if (person[name] > person[maxperson]) {
            maxperson = name;
        }
    }
    std::cout << maxperson;
    return 0;
}


/*
A. Winner
time limit per test1 second
memory limit per test64 megabytes
inputstandard input
outputstandard output
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.

Input
The first line contains an integer number n (1  ≤  n  ≤  1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.

Output
Print the name of the winner.

Sample test(s)
input
3
mike 3
andrew 5
mike 2
output
andrew
input
3
andrew 3
andrew 2
mike 5
output
andrew
*/

#include <iostream>
#include <map>
#include <vector>
#include <set>

int n;
std::string name;
int score;
int maxscore = -2147483648;
std::map<std::string, int> person;
typedef struct {
    std::string name;
    int score;
} entry;
std::vector<entry> in;
entry temp;
std::set<std::string> maxperson;

int main(int argc, char* argv[]) {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> name >> score;
        temp.name = name;
        temp.score = score;
        in.push_back(temp);
        if (person.find(name) == person.end()) {
            person[name] = score;
        } else {
            person[name] += score;
        }
    }
    std::map<std::string, int>::iterator mapit;
    maxperson.clear();
    for (mapit = person.begin(); mapit != person.end(); mapit++) {
        if (mapit->second > maxscore) {
            maxscore = mapit->second;
            maxperson.clear();
            maxperson.insert(mapit->first);
        }
        else if (mapit->second == maxscore) {
            maxperson.insert(mapit->first);
        }
    }
    person.clear();
    std::vector<entry>::iterator it;
    for (it = in.begin(); it != in.end(); it++) {
        if (person.find(it->name) == person.end()) {
            person[it->name] = it->score;
        } else {
            person[it->name] += it->score;
        }
        if ((person[it->name] >= maxscore) && (maxperson.count(it->name) == 1)) {
            std::cout << it->name << std::endl;
            return 0;
        }
    }
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001],has[1001],check[1001],sc[1001];
string strs[1001],names[1001];

int n;
int find(string s,int k){
   for(int i=0;i<k;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0,c=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<n;i++){
       cin>>s>>a;
       names[i]=s;
       sc[i]=a;
       if(i==0)s0=s;
       b=find(s,k);
       if(b==-1){
         b=k;
         strs[b]=s;
         k++;
       }
        hash[b]+=a;
    }
    for(int i=0;i<k;i++)if(hash[i]>max)max=hash[i];
    for(int i=0;i<k;i++)if(hash[i]==max)check[i]=1;
    for(int i=0;i<n;i++){
        b=find(names[i],k);
        if(check[b]==1){
             has[b]+=sc[i];
             if(has[b]==max){
                 s0=names[i];
                 break;
             }
        }
    }
    cout<<s0<<endl;
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001];
string strs[1001];
int n;
int find(string s){
   for(int i=0;i<n;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<=n;i++)strs[i]="";
    for(int i=0;i<n;i++){
       cin>>s>>a;
       b=find(s);

       if(b==-1){
          b=k;
          strs[k++]=s;
       }
       hash[b]+=a;
       if(hash[b]>max){
         max=hash[b];
         s0=strs[b];
       }
    }
    cout<<s0<<endl;
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001];
string strs[1001];

int n;
int find(string s,int k){
   for(int i=0;i<k;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0,c=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<n;i++){
       cin>>s>>a;
       if(i==0)s0=s;
       b=find(s,k);
       if(b==-1){
         b=k;
         strs[b]=s;

         k++;
       }
        hash[b]+=a;
       if(b==c && hash[b]<max){
         max=hash[b];
         for(int j=0;j<k;j++){
            if(hash[j]>max){
               max=hash[j];
               s0=strs[j];
               c=j;
            }
         }
       }
       if(hash[b]>max){
         max=hash[b];
         s0=strs[b];
         c=b;
       }
    }
    cout<<s0<<endl;
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001],has[1001];
string strs[1001];
string names[1001];
int scores[1001];
int n;
int find(string s){
   for(int i=0;i<n;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<=n;i++)strs[i]="";
    for(int i=0;i<n;i++){
       cin>>s>>a;
       names[i]=s;
       scores[i]=a;
       b=find(s);
       if(b==-1){
          b=k;
          strs[k++]=s;
       }
       if(a<0){hash[b]=-1;continue;}
       hash[b]+=a;
    }
    for(int i=0;i<n;i++)if(hash[i]>max)max=hash[i];
    flag f=false;
    for(int i=0;i<n;i++){
      b=find(names[i]);
      if(scores[i]<0)has[b]=-1;
      if(has[b]!=-1){
         has[b]+=scores[i];
         if(has[b]==max){
             cout<<names[i]<<endl;
             f=true;
             break;
         }
      }
      if(f)break;
    }

    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001],has[1001];
string strs[1001];
string names[1001];
int scores[1001];
int n;
int find(string s){
   for(int i=0;i<n;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<=n;i++)strs[i]="";
    for(int i=0;i<n;i++){
       cin>>s>>a;
       names[i]=s;
       scores[i]=a;
       b=find(s);
       if(b==-1){
          b=k;
          strs[k++]=s;
       }
       if(a<0){hash[b]=-1;continue;}
       if(hash[b]!=-1)
       hash[b]+=a;
    }
    for(int i=0;i<n;i++)if(hash[i]>max)max=hash[i];
    bool f=false;
    for(int i=0;i<n;i++){
      b=find(names[i]);
      if(scores[i]<0)has[b]=-1;
      if(has[b]!=-1){
         has[b]+=scores[i];
         if(has[b]==max){
            s0=strs[b];
             f=true;
             break;
         }
      }
      if(f)break;
    }
    cout<<s0<<endl;
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001],has[1001],check[1001],sc[1001];
string strs[1001],names[1001];

int n;
int find(string s,int k){
   for(int i=0;i<k;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0,c=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<n;i++){
       cin>>s>>a;
       names[i]=s;
       sc[i]=a;
       if(i==0)s0=s;
       b=find(s,k);
       if(b==-1){
         b=k;
         strs[b]=s;
         k++;
       }
        hash[b]+=a;
    }
    for(int i=0;i<k;i++)if(hash[i]>max)max=hash[i];
    for(int i=0;i<k;i++)if(hash[i]==max)check[i]=1;
    bool f=false;
    for(int i=0;i<n;i++){
        b=find(names[i],k);
        if(check[b]==1){
             has[b]+=sc[i];
             if(has[b]>=max){
                 s0=names[i];
                 f=true;
                 break;
             }
        }
        if(f)break;
    }
    cout<<s0<<endl;
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001],has[1001];
string strs[1001];
string names[1001];
int scores[1001];
int n;
int find(string s){
   for(int i=0;i<n;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<=n;i++)strs[i]="";
    for(int i=0;i<n;i++){
       cin>>s>>a;
       names[i]=s;
       scores[i]=a;
       b=find(s);
       if(b==-1){
          b=k;
          strs[k++]=s;
       }
       if(a<0){hash[b]=-1;continue;}
       hash[b]+=a;
    }
    for(int i=0;i<n;i++)if(hash[i]>max)max=hash[i];
    bool f=false;
    for(int i=0;i<n;i++){
      b=find(names[i]);
      if(scores[i]<0)has[b]=-1;
      if(has[b]!=-1){
         has[b]+=scores[i];
         if(has[b]==max){
             cout<<names[i]<<endl;
             f=true;
             break;
         }
      }
      if(f)break;
    }

    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001],has[1001],check[1001],sc[1001];
string strs[1001],names[1001];

int n;
int find(string s,int k){
   for(int i=0;i<k;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0,c=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<n;i++){
       cin>>s>>a;
       names[i]=s;
       sc[i]=a;
       if(i==0)s0=s;
       b=find(s,k);
       if(b==-1){
         b=k;
         strs[b]=s;
         k++;
       }
        hash[b]+=a;
    }
    for(int i=0;i<k;i++)if(hash[i]>max)max=hash[i];
    for(int i=0;i<k;i++)if(hash[i]==max)check[i]=1;
    for(int i=0;i<n;i++){
        b=find(names[i],k);
        if(check[b]==1){
             has[b]+=sc[b];
             if(has[b]==max){
                 s0=names[i];
                 break;
             }
        }
    }
    cout<<s0<<endl;
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[10000];
string strs[20000];
int strhash(string s){
   int sum=0;
   for(int i=0;i<s.length();i++){
      sum+=(s[i]-97)*(i+2);
   }
   return sum;
}

int main(){
    int n,a,b,max=0;
    string s,s0;
    cin>>n;
    while(n--){
       cin>>s>>a;
       b=strhash(s);
       strs[b]=s;
       hash[b]+=a;
       if(hash[b]>max){
         max=hash[b];
         s0=strs[b];
       }
    }
    cout<<s0<<endl;
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[14000];
string strs[14000];
int strhash(string s){
   int sum=0;
   for(int i=0;i<s.length();i++){
      sum+=(s[i]-97)*(i+1);
   }
   return sum;
}

int main(){
    int n,a,b,max=0;
    string s,s0;
    cin>>n;
    while(n--){
       cin>>s>>a;
       b=strhash(s);
       strs[b]=s;
       hash[b]+=a;
       if(hash[b]>max){
         max=hash[b];
         s0=strs[b];
       }
    }
    cout<<s0<<endl;
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001],has[1001];
string strs[1001];
string names[1001];
int scores[1001];
int n;
int find(string s){
   for(int i=0;i<n;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<=n;i++)strs[i]="";
    for(int i=0;i<n;i++){
       cin>>s>>a;
       names[i]=s;
       scores[i]=a;
       b=find(s);
       if(b==-1){
          b=k;
          strs[k++]=s;
       }
       hash[b]+=a;
    }
    for(int i=0;i<n;i++)if(hash[i]>max)max=hash[i];
    bool f=false;
    for(int i=0;i<n;i++){
      b=find(names[i]);
      has[b]+=scores[i];
         if(has[b]==max){
            s0=strs[b];
             f=true;
             break;
         }
      if(f)break;
    }
    cout<<s0<<endl;
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001],has[1001];
string strs[1001];
string names[1001];
int scores[1001];
int n;
int find(string s){
   for(int i=0;i<n;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<=n;i++)strs[i]="";
    for(int i=0;i<n;i++){
       cin>>s>>a;
       names[i]=s;
       scores[i]=a;
       b=find(s);
       if(b==-1){
          b=k;
          strs[k++]=s;
       }
       if(a<0){hash[b]=-1;continue;}
       if(hash[b]!=-1)
       hash[b]+=a;
    }
    for(int i=0;i<n;i++)if(hash[i]>max)max=hash[i];
    bool f=false;
    for(int i=0;i<n;i++){
      b=find(names[i]);
      if(scores[i]<0)has[b]=-1;
      if(has[b]!=-1){
         has[b]+=scores[i];
         if(has[b]==max){
             cout<<names[i]<<endl;
             f=true;
             break;
         }
      }
      if(f)break;
    }
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001];
string strs[1001];

int n;
int find(string s,int k){
   for(int i=0;i<k;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<n;i++){
       cin>>s>>a;
       if(i==0)s0=s;
       b=find(s,k);
       if(b==-1){
         b=k;
         strs[b]=s;
         hash[b]+=a;
         k++;
       }
       if(hash[b]>max){
         max=hash[b];
         s0=strs[b];
       }
    }
    cout<<s0<<endl;
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001],has[1001];
string strs[1001];
string names[1001];
int scores[1001];
int n;
int find(string s){
   for(int i=0;i<n;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<=n;i++)strs[i]="";
    for(int i=0;i<n;i++){
       cin>>s>>a;
       names[i]=s;
       scores[i]=a;
       b=find(s);
       if(b==-1){
          b=k;
          strs[k++]=s;
       }
       if(a<0){hash[b]=-1;continue;}
       hash[b]+=a;
    }
    for(int i=0;i<n;i++)if(hash[i]>max)max=hash[i];
    for(int i=0;i<n;i++){
      b=find(names[i]);
      if(scores[i]<0)has[b]=-1;
      if(has[b]!=-1){
         has[b]+=scores[i];
         if(has[b]==max){
             cout<<names[i]<<endl;
             break;
         }
      }
    }

    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[1001];
string strs[1001];

int n;
int find(string s,int k){
   for(int i=0;i<k;i++){
     if(strs[i]==s)return i;
   }
   return -1;
}
int main(){
    int a,b,k=0,max=0;
    string s,s0;
    cin>>n;
    for(int i=0;i<n;i++){
       cin>>s>>a;
       if(i==0)s0=s;
       b=find(s,k);
       if(b==-1){
         b=k;
         strs[b]=s;

         k++;
       }
        hash[b]+=a;
       if(hash[b]>max){
         max=hash[b];
         s0=strs[b];
       }
    }
    cout<<s0<<endl;
    return 0;
}


#include"iostream"
#include"string"
using namespace std;
int hash[20000];
string strs[20000];
int strhash(string s){
   int sum=0;
   for(int i=0;i<s.length();i++){
      sum+=(s[i]-97)*(i+2);
   }
   return sum;
}

int main(){
    int n,a,b,max=0;
    string s,s0;
    cin>>n;
    while(n--){
       cin>>s>>a;
       b=strhash(s);
       strs[b]=s;
       hash[b]+=a;
       if(hash[b]>max){
         max=hash[b];
         s0=strs[b];
       }
    }
    cout<<s0<<endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,pair<int,int> > myMap;
  map<string,pair<int,int> >::iterator it;
  string winner;
  int max = -2000000;
  int index = 2000000;
	scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
    if(score >0)
	  myMap[name] = make_pair(i,myMap[name].second+score);
    else
    myMap[name] = make_pair(myMap[name].first,myMap[name].second+score);
  }
  for(it=myMap.begin();it!=myMap.end();it++){
    if(it->second.second>max || (it->second.second==max && it->second.first<index)){
      winner = it->first;
      max = it->second.second;
      index = it->second.first;
    }
  }
  cout << winner << endl;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,pair<int,int> > myMap;
  map<string,pair<int,int> >::iterator it;
  string winner;
  int max = -2000000;
  int index = 2000000;
	scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
	  myMap[name] = make_pair(i,mymap[Name]->second+score);
  }
  for(it=myMap.begin();it!=myMap.end();it++){
    if(it->second->second>max || (it->second->second==max && it->second->first<index)){
      winner = it->first;
      max = it->second->second;
      index = it->secode->first;
    }
  }
  cout << winner << endl;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <vector>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,int> myMap;
  vector<pair<int,pair<int,string> > > myVector;
	scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
	myMap[name] += score;
	myVector.push_back(make_pair(-1*myMap[name],make_pair(i,name)));
  }
  cout <<myVector.begin()->second.second;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <vector>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,int> myMap;
  vector<pair<int,pair<int,string> > > myVector;
  string winner;
  int max = -2000000;
  int index = 2000000;
	scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
	myMap[name] += score;
	myVector.push_back(make_pair(myMap[name],make_pair(i,name)));
  }
  cout <<myVector.begin()->second.second;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <vector>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,int> myMap;
  vector<pair<int,pair<int,string> > > myVector;
  string winner;
  int max = -2000000;
  int index = 2000000;
	scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
	myMap[name] += score;
	myVector.push_back(make_pair(myMap[name],make_pair(-1*i,name)));
  }
  cout <<myVector.begin()->second.second;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,int> myMap;
  string winner;
  int max = -1000000000;
	scanf("%d",&n);
  while(n-->0){
    cin >> name;
    scanf("%d",&score);
	  myMap[name] += score;
    if(myMap[name]>max) winner = name;
  }
  cout << winner << endl;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <vector>
using namespace std;

int main() {
	int n;
  int score;
  int max = -200000;
  string name;
  map<string,int> myMap;
  vector<pair<int,pair<int,string> > > myVector;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
	myMap[name] += score;
	myVector.push_back(make_pair(-1*myMap[name],make_pair(i,name)));
  }
  for(map<string,int>::iterator it = myMap.begin();it != myMap.end();it++){
    if(it->second > max) max = it->second;
  }
  sort(myVector.begin(),myVector.end());
  for(vector<pair<int,pair<int,string> > >::iterator it= myVector.begin();it !=myVector.end();it++){
    if(it->first == -1*max){
      cout << it->second.second;
      break;
    }
  }
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,int> myMap;
  string winner;
  int max = -1000000000;
	scanf("%d",&n);
  while(n-->0){
    cin >> name;
    scanf("%d",&score);
	  myMap[name] += score;
    if(myMap[name]>max) winner = name;
  }
  printf("%s\n",winner);
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,int> myMap;
  string winner;
  int max = -1000000000;
	scanf("%d",&n);
  while(n-->0){
    cin >> name;
    scanf("%d",&score);
	  myMap[name] += score;
    if(myMap[name]>max){
      winner = name;
      max = myMap[name];
    }
  }
  cout << winner << endl;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,int> myMap;
  map<string,int>::iterator it;
  string winner;
  int max = -2000000;
	scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
	  myMap[name] += score;
  }
  for(it=myMap.begin();it!=myMap.end();it++){
    if(it->second>max){
      winner = it->first;
      max = it->second;
    }
    cout << it->first << it->second;
  }
  cout << winner << endl;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,pair<int,int> > myMap;
  map<string,pair<int,int> >::iterator it;
  string winner;
  int max = -2000000;
  int index = 2000000;
	scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
	  myMap[name] = make_pair(i,myMap[name].second+score);
  }
  for(it=myMap.begin();it!=myMap.end();it++){
    if(it->second.second>max || (it->second.second==max && it->second.first<index)){
      winner = it->first;
      max = it->second.second;
      index = it->second.first;
    }
  }
  cout << winner << endl;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,int> myMap;
  map<string,int>::iterator it;
  string winner;
  int max = -2000000;
	scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
	  myMap[name] += score;
  }
  for(it=myMap.begin();it!=myMap.end();it++){
    if(it->second>max){
      winner = it->first;
      max = it->second;
    }
  }
  cout << winner << endl;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,pair<int,int> myMap;
  map<string,pair<int,int>::iterator it;
  string winner;
  int max = -2000000;
  int index = 2000000;
	scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
	  myMap[name] = make_pair(i,mymap[Name]->second+score);
  }
  for(it=myMap.begin();it!=myMap.end();it++){
    if(it->second->second>max || (it->second->second==max && it->second->first<index){
      winner = it->first;
      max = it->second->second;
      index = it->secode->first;
    }
  }
  cout << winner << endl;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,pair<int,int> > myMap;
  map<string,pair<int,int> >::iterator it;
  string winner;
  int max = -2000000;
  int index = 2000000;
	scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
	  myMap[name] = make_pair(i,myMap[name]->second+score);
  }
  for(it=myMap.begin();it!=myMap.end();it++){
    if(it->second.second>max || (it->second.second==max && it->second.first<index)){
      winner = it->first;
      max = it->second.second;
      index = it->secode.first;
    }
  }
  cout << winner << endl;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
using namespace std;
const double PI  =3.141592653589793238463;
double gcd(double a,double b){
  if(fabs(a)<=0.01) return b;
  if(fabs(b)<=0.01) return a;
  return gcd(b,fmod(a,b));
}
int main() {
  double x[3],y[3];
  double z[3];
  double angle[3];
  double r;
  for(int i=0;i<3;i++){
    scanf("%lf %lf",&x[i],&y[i]);
  }
  for(int i=0;i<3;i++){
  z[i] = sqrt((x[(i+1)%3]-x[i])*(x[(i+1)%3]-x[i])+(y[(i+1)%3]-y[i])*(y[(i+1)%3]-y[i]));
  }
  r = z[0]*z[1]*z[2]/sqrt((z[0]+z[1]+z[2])*(z[0]+z[1]-z[2])*(z[0]-z[1]+z[2])*(z[1]-z[0]+z[2]));
  for(int i=0;i<3;i++){
    angle[i] = acos(1.0-z[i]*z[i]/(2*r*r));
  }
  angle[2] = 2*acos(-1.0) -angle[0]-angle[1];
  double min = gcd(angle[0],gcd(angle[1],angle[2]));
  printf("%.8lf\n",r*r*sin(min)/2*(2*acos(-1.0)/min));
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <vector>
using namespace std;

int main() {
	int n;
  int score;
  int max = -200000;
  string name;
  map<string,pair<int,int> > myMap;
  vector<pair<int,pair<int,string> > > myVector;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
	myMap[name] = make_pair(myMap[name].first+score,0);
	myVector.push_back(make_pair(i,make_pair(-1*myMap[name].first,name)));
  }
  for(map<string,pair<int,int> >::iterator it = myMap.begin();it != myMap.end();it++){
    if(it->second.first > max) max = it->second.first;
  }
  for(map<string,pair<int,int> >::iterator it = myMap.begin();it != myMap.end();it++){
    if(it->second.first == max) it->second.second = 1;
  }
  sort(myVector.begin(),myVector.end());
  for(vector<pair<int,pair<int,string> > >::iterator it= myVector.begin();it !=myVector.end();it++){
    if(it->second.first <= -1*max && myMap[it->second.second].second){
      cout << it->second.second;
      break;
    }
  }
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,int> myMap;
  string winner;
  int max = -2000000;
	scanf("%d",&n);
  while(n-->0){
    cin >> name;
    scanf("%d",&score);
	  myMap[name] += score;
    if(myMap[name]>max){
      winner = name;
      max = myMap[name];
    }
  }
  cout << winner << endl;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <vector>
using namespace std;

int main() {
	int n;
  string name;
  int score;
  map<string,int> myMap;
  vector<pair<int,pair<int,string> > > myVector;
	scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> name;
    scanf("%d",&score);
	myMap[name] += score;
	myVector.push_back(make_pair(-1*myMap[name],make_pair(i,name)));
  }
  sort(myVector.begin(),myVector.end());
  cout <<myVector.begin()->second.second;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  if(i.scores < j.scores) return true;
  if(i.scores == j.scores && i.move > j.move) return true;
  return false;
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  if(n > 550) {
      cout << v[v.size()-1].name << " " << v[v.size()-1].scores << " " << v[v.size()-1].move << "\n";
      cout << v[v.size()-2].name << " " << v[v.size()-2].scores << " " << v[v.size()-2].move << "\n";
  } else {
    cout << v[v.size()-1].name << "\n";
  }
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  bool answer;
  if(i.scores > j.scores) return true;
  if(i.scores == j.scores && i.move < j.move) return true;
  return false;
}

int main() {
  int m = 10000;
  //ifstream in("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      elem->move = i;
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  cout << v[0].name << "\n";
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  return (i.scores < j.scores);
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  std::vector<string> names_vect;
  vector<int> scores_vect;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    names_vect.push_back(s);
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      scores_vect.push_back(scores);
      g.name = s;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      scores_vect.push_back(elem->scores);
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  int maxscore = v[v.size()-1].scores;
  for(int i = 0; i < names_vect.size(); i++) {
    if(scores_vect[i] >= maxscore) {
      cout << names_vect[i] << "\n";
      return 0;
    }
  }
  return 0;
}