#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
	string s;
	cin>>s;
	vector<int>ok;
	for(char x: s)
	{
		ok.push_back((int)x);
	}
	sort(ok.begin(),ok.end());
	int x=ok.size();
	if(ok[x-1]-ok[0]+1==x)
	{
		cout<<"Yes"<<endl;
	}
	else{ cout<<"No"<<endl;
	}
}
}


typedef long long ll;
//typedef vector<int> vi;
#define PB push_back
#define MP make_pair
//#define REP(i,a,b) for (int i = a; i <= b; i++)

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int flag=0;
        string s;
        cin>>s;
        int a[26]={0};
        int l=s.size();
        for(int i=0;i<l;i++){
            if(l>26)
                break;
            else{
                int in=s[i]-'a';
                a[in]++;
            }
        }
        int cnt=0;
        for(int i=0;i<26;i++){
            if(a[i]==1){
                cnt++;
            }
            if(a[i]==0 && cnt>0 && l<i){
                flag=1;
                break;
            }
            if(a[i]>1)
                flag=1;
            if(l==1)
                flag=0;

        }
        if(flag==0)
            puts("Yes");
        else
            puts("No");

    }
}


typedef long long ll;
//typedef vector<int> vi;
#define PB push_back
#define MP make_pair
//#define REP(i,a,b) for (int i = a; i <= b; i++)

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int flag=0;
        string s;
        cin>>s;
        int a[26]={0};
        int l=s.size();
        for(int i=0;i<l;i++){
            if(l>26)
                break;
            else{
                int in=s[i]-'a';
                a[in]++;
            }
        }
        int cnt=0;
        for(int i=0;i<26;i++){
            if(a[i]==1){
                cnt++;
            }
            if(a[i]==0 && cnt>0 && i<(l-1)){
                flag=1;
                break;
            }
            if(a[i]>1)
                flag=1;

        }
        if(flag==0)
            puts("Yes");
        else
            puts("No");

    }
}


typedef long long ll;
//typedef vector<int> vi;
#define PB push_back
#define MP make_pair
//#define REP(i,a,b) for (int i = a; i <= b; i++)

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int flag=0;
        string s;
        cin>>s;
        int a[26]={0};
        int l=s.size();
        for(int i=0;i<l;i++){
            if(l>26)
                break;
            else{
                int in=s[i]-'a';
                a[in]++;
            }
        }
        int i=0;
        int cnt=0;
        while(a[i]!=1){
                for(int j=i;j<l;j++){
                    if(a[j]==1)
                        cnt++;
                    // if(a[j]>1)
                    //     cnt--;
                    if(cnt==l)
                        break;
                }
            i++;
            if(a[i]==1)
                break;
        }
            //     if(a[i]==0)
            //         flag==1;
            //     // if(a[i-1]==1)
            //     // flag=0;
            // }
            // else
            //     flag=1;
            //     flag=1;
            //     break;
            // }
            // else if(a[i]>1)
            //     flag=1;
            // if(l==1)
            //     flag=0;

        //}
        if(cnt==l)
            puts("Yes");
        else
            puts("No");

    }
}


typedef long long ll;
//typedef vector<int> vi;
#define PB push_back
#define MP make_pair
//#define REP(i,a,b) for (int i = a; i <= b; i++)

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int flag=0;
        string s;
        cin>>s;
        int a[26]={0};
        int l=s.size();
        for(int i=0;i<l;i++){
            if(l>26)
                break;
            else{
                int in=s[i]-'a';
                a[in]++;
            }
        }
        int cnt=0;
        for(int i=0;i<26;i++){
            if(a[i]==1){
                cnt++;
            }
            if(a[i]==0 && cnt>0)
                flag==1;

        }
        if(flag==0)
            puts("Yes");
        else
            puts("No");

    }
}


typedef long long ll;
//typedef vector<int> vi;
#define PB push_back
#define MP make_pair
//#define REP(i,a,b) for (int i = a; i <= b; i++)

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int flag=0;
        string s;
        cin>>s;
        int a[26]={0};
        int l=s.size();
        for(int i=0;i<l;i++){
            if(l>26)
                break;
            else{
                int in=s[i]-'a';
                a[in]++;
            }
        }
        int cnt=0;
        for(int i=0;i<26;i++){
            if(a[i]==1){
                cnt++;
            }
            if(a[i]==0 && cnt>0 && i<l){
                flag=1;
                break;
            }
            if(a[i]>1)
                flag=1;

        }
        if(flag==0)
            puts("Yes");
        else
            puts("No");

    }
}


typedef long long ll;
//typedef vector<int> vi;
#define PB push_back
#define MP make_pair
//#define REP(i,a,b) for (int i = a; i <= b; i++)

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int flag=0;
        string s;
        cin>>s;
        int a[26]={0};
        int l=s.size();
        for(int i=0;i<l;i++){
            if(l>26)
                break;
            else{
                int in=s[i]-'a';
                a[in]++;
            }
        }
        int i=0;
        int cnt=0;
        for(i=0;i<26;i++){
                if(a[i]==1){
                int m=i;
                for(int j=i;j<l+m;j++){
                    if(a[j]==1)
                        cnt++;
                    // if(a[j]>1)
                    //     cnt--;
                    if(cnt==l)
                        break;
                }
            }
            // i++;
            if(a[i]==1)
                break;
        //i++;
        }
                    //     if(a[i]==0)
            //         flag==1;
            //     // if(a[i-1]==1)
            //     // flag=0;
            // }
            // else
            //     flag=1;
            //     flag=1;
            //     break;
            // }
            // else if(a[i]>1)
            //     flag=1;
            // if(l==1)
            //     flag=0;

        //}
        if(cnt==l)
            puts("Yes");
        else
            puts("No");

    }
}


typedef long long ll;
//typedef vector<int> vi;
#define PB push_back
#define MP make_pair
//#define REP(i,a,b) for (int i = a; i <= b; i++)

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int flag=0;
        string s;
        cin>>s;
        int a[26]={0};
        int l=s.size();
        for(int i=0;i<l;i++){
            if(l>26)
                break;
            else{
                int in=s[i]-'a';
                a[in]++;
            }
        }
        int cnt=0;
        for(int i=0;i<26;i++){
            if(a[i]==1){
                cnt++;
            }
            if(a[i]==0 && cnt>0 && l<i){
                flag=1;
                break;
            }
            if(a[i]>1)
                flag=1;

        }
        if(flag==0)
            puts("Yes");
        else
            puts("No");

    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long int t,i,c=0;
    cin>>t;
    while(t--)
    {
    string s;
    cin>>s;
    int h[26]={0};
    for(i=0;i<s.length();i++)
    h[s[i]-'a']++;
    for(i=0;i<26;i++)
    {
        if(h[i]>1)
        c=1;
    }
    if(c!=1)
    {
    for(i=0;i<s.length()-1;i++)
    {
        if(abs(s[i]-s[i+1])==1)
        {
            cout<<"YES"<<endl;
            break;
        }
    }
    if(s.length()==1)
    cout<<"YES"<<endl;
    else if(i==s.length()-1)
    cout<<"NO"<<endl;
    }
    else
    cout<<"NO"<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {

	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
	    int c=0;
	    string s;
	    cin>>s;
	    sort(s.begin(),s.end());
	    for(int j=1;j<s.length();j++)
	    {
	        if((s[j]-s[j-1])!=1)
	        {
	            c=1;
	            cout<<"No"<<endl;
	            break;
	        }
	    }
	    if(c==0)
	    cout<<"Yes"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long int t,i,c=0;
    cin>>t;
    while(t--)
    {
    string s;
    cin>>s;
    if(s.length()==1)
    cout<<"YES"<<endl;
    else
    {
    int h[26]={0};
    for(i=0;i<s.length();i++)
    h[s[i]-'a']++;
    for(i=0;i<26;i++)
    {
        if(h[i]>1)
        c=1;
    }
    if(c!=1)
    {
    for(i=0;i<s.length()-1;i++)
    {
        if(abs(s[i]-s[i+1])==1)
        {
            cout<<"YES"<<endl;
            break;
        }
    }
    if(i==s.length()-1)
    cout<<"NO"<<endl;
    }
    else
    cout<<"NO"<<endl;
    }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long int t,i,c=0;
    cin>>t;
    while(t--)
    {
    string s;
    cin>>s;
    int h[26]={0};
    for(i=0;i<s.length();i++)
    h[s[i]-'a']++;
    for(i=0;i<26;i++)
    {
        if(h[i]>1)
        c=1;
    }
    if(c!=1)
    {
    for(i=0;i<s.length()-1;i++)
    {
        if(abs(s[i]-s[i+1])==1)
        {
            cout<<"YES"<<endl;
            break;
        }
    }
    if(s.length()==1)
    cout<<"YES"<<endl;
    if(i==s.length()-1&&s.length()!=1)
    cout<<"NO"<<endl;
    }
    else
    cout<<"NO"<<endl;
    }
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d\n",&n);
	for(int kk=1;kk<=n;kk++)
	{
		char p[110];
		int a[310];
		for(int i=0;i<=300;i++)
			a[i]=0;
		scanf("%s",p);
		int ll=strlen(p);
		for(int i=0;i<ll;i++)
			a[p[i]]++;
		int l=1,f=0,r=300;
		for(int i=0;i<=300;i++)
			if(a[i])
			{
				l=i;
				break;
			}
		for(int i=l;i<=300;i++)
		{
			if(a[i]>1)
			{
				printf("No\n");
				f=1;
			}
			if(a[i]==0)
			{
				r=i;
				break;
			}
		}
		if(f==0)
		{
			int f2=1;
			for(int i=r+1;i<=300;i++)
				if(a[i])
					f2=0;
			if(f2==1)
				printf("Yes\n");
			if(f2==0)
				printf("No\n");
		}

	}
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d\n",&n);
	for(int kk=1;kk<=n;kk++)
	{
		char p[110];
		scanf("%s",p);
		int a[110];
		int l=strlen(p);
		for(int i=0;i<l;i++)
			a[i]=p[i]-97;
		sort(a,a+l);
		int k=a[0],f=0;
		for(int i=1;i<l;i++)
			if(a[i]-k!=i)
			{
				printf("No\n");
				f=1;
				break;
			}
		if(f==0)
			printf("Yes\n");
	}
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d\n",&n);
	for(int kk=1;kk<n;kk++)
	{
		char p[110];
		int a[310];
		for(int i=0;i<=300;i++)
			a[i]=0;
		scanf("%s",p);
		int ll=strlen(p);
		for(int i=0;i<ll;i++)
			a[p[i]]++;
		int l=1,f=0,r=300;
		for(int i=0;i<=300;i++)
			if(a[i])
			{
				l=i;
				break;
			}
		for(int i=l;i<=300;i++)
		{
			if(a[i]>1)
			{
				printf("No\n");
				f=1;
			}
			if(a[i]==0)
			{
				r=i;
				break;
			}
		}
		if(f==0)
		{
			int f2=1;
			for(int i=r+1;i<=300;i++)
				if(a[i])
					f2=0;
			if(f2==1)
				printf("Yes\n");
			if(f2==0)
				printf("No\n");
		}
	}
	char p[110];
		int a[310];
		for(int i=0;i<=300;i++)
			a[i]=0;
		scanf("%s",p);
		int ll=strlen(p);
		for(int i=0;i<ll;i++)
			a[p[i]]++;
		int l=1,f=0,r=300;
		for(int i=0;i<=300;i++)
			if(a[i])
			{
				l=i;
				break;
			}
		for(int i=l;i<=300;i++)
		{
			if(a[i]>1)
			{
				printf("No");
				f=1;
			}
			if(a[i]==0)
			{
				r=i;
				break;
			}
		}
		if(f==0)
		{
			int f2=1;
			for(int i=r+1;i<=300;i++)
				if(a[i])
					f2=0;
			if(f2==1)
				printf("Yes");
			if(f2==0)
				printf("No");
		}
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d\n",&n);
	for(int kk=1;kk<n;kk++)
	{
		char p[110];
		for(int i=0;i<=100;i++)
			p[i]=0;
		int a[310];
		for(int i=0;i<=300;i++)
			a[i]=0;
		scanf("%s",p);
		int ll=strlen(p);
		for(int i=0;i<ll;i++)
			a[p[i]]++;
		int l=1,f=0,r=300;
		for(int i=0;i<=300;i++)
			if(a[i])
			{
				l=i;
				break;
			}
		for(int i=l;i<=300;i++)
		{
			if(a[i]>1)
			{
				printf("No\n");
				f=1;
			}
			if(a[i]==0)
			{
				r=i;
				break;
			}
		}
		if(f==0)
		{
			int f2=1;
			for(int i=r+1;i<=300;i++)
				if(a[i])
					f2=0;
			if(f2==1)
				printf("Yes\n");
			if(f2==0)
				printf("No\n");
		}
	}
	char p[110];
		int a[310];
		for(int i=0;i<=300;i++)
			a[i]=0;
		scanf("%s",p);
		int ll=strlen(p);
		for(int i=0;i<ll;i++)
			a[p[i]]++;
		int l=1,f=0,r=300;
		for(int i=0;i<=300;i++)
			if(a[i])
			{
				l=i;
				break;
			}
		for(int i=l;i<=300;i++)
		{
			if(a[i]>1)
			{
				printf("No");
				f=1;
			}
			if(a[i]==0)
			{
				r=i;
				break;
			}
		}
		if(f==0)
		{
			int f2=1;
			for(int i=r+1;i<=300;i++)
				if(a[i])
					f2=0;
			if(f2==1)
				printf("Yes");
			if(f2==0)
				printf("No");
		}
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d\n",&n);
	for(int kk=1;kk<=n;kk++)
	{
		char p[110];
		int a[27];
		for(int i=1;i<=26;i++)
			a[i]=0;
		scanf("%s",p);
		int ll=strlen(p);
		for(int i=0;i<ll;i++)
			a[p[i]-'a'+1]++;
		int l=1,f=0,r=26;
		for(int i=1;i<=26;i++)
			if(a[i])
			{
				l=i;
				break;
			}
		for(int i=l;i<=26;i++)
		{
			if(a[i]>1)
			{
				printf("No\n");
				f=1;
			}
			if(a[i]==0)
			{
				r=i;
				break;
			}
		}
		if(f==0)
		{
			int f2=1;
			for(int i=r+1;i<=26;i++)
				if(a[i])
					f2=0;
			if(f2==1)
				printf("Yes\n");
			if(f2==0)
				printf("No\n");
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   while(n--)
   {
      string s;
      cin>>s;
      sort(s,s+n);
      bool f=1;
      for(int i=0;i<s.size();i++)
      {
         if(s[i]==s[i+1])
      f=0;
      }
      cout<<(f?"Yes":"No")<<endl;

   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   while(n--)
   {
      string s;
      cin>>s;
      sort(s.begin(),s.end());
      bool f=0;
      for(int i=1;i<s.size();i++)
      {
         if(s[i]!=s[i-1])
         f=1;
      }
      cout<<(f?"Yes":"No")<<endl;

   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   while(n--)
   {
      string s;
      cin>>s;
      sort(s.begin(),s.end());
      bool f=0;
      for(int i=1;i<s.size();i++)
      {
         if(s[i]!=s[i-1]+1)
         f=1;
      }
      cout<<(f?"Yes":"No")<<endl;

   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   while(n--)
   {
      string s;
      cin>>s;
      sort(s.begin(),s.end());
      bool f=0;
      for(int i=0;i<s.size();i++)
      {
         if(s[i]!=s[i+1])
         f=1;
      }
      cout<<(f?"Yes":"No")<<endl;

   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   while(n--)
   {
      string s;
      cin>>s;
      sort(s.begin(),s.end());
      bool f=1;
      for(int i=0;i<s.size();i++)
      {
         if(s[i]==s[i+1])
      f=0;

      }
      cout<<(f?"Yes":"No")<<endl;

   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,i,f;string s;
int main(){
	for(cin>>n;n--;){
		cin>>s;
		sort(s.begin(),s.end());
		for(f=0,i=1;i<s.size();i++)f|=s[i]!=(s[i-1]+1);
		cout<<(f?"No\n":"Yes\n");
	}
}


#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define MAX_CHAR 26
using namespace std;

string sortString(string &str)
{
    string ans;
    int charCount[MAX_CHAR] = {0};
    for (int i=0; i<str.length(); i++)
        charCount[str[i]-'a']++;

    for (int i=0;i<MAX_CHAR;i++)
        for (int j=0;j<charCount[i];j++)
            ans.push_back((char)('a'+i));

    return ans;
}

void work(){
    int t,l;
    cin >> t;
    string str;
    int ans[t];
    for(int i=0;i<t;i++){
        l=1;
        cin >> str;
        str = sortString(str);
        while(l < str.size() && str[l] -str[l-1]==1 ){
            l++;
        }
        if(l < str.size()){ans[i]=0;}
        else{ans[i]=1;}
    }
    for(int j=0;j<t;j++){
        ans[j]==1? cout << "Yes" << "\n" : cout << "No" << "\n";
    }

}

int main(){
    work();

    return 0;

}


#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#include <string.h>
using namespace std;
int ans[104];

bool uniqueCharacters(char *str)
{

    // If at any time we encounter 2
    // same characters, return false
    for (int i = 0; i < strlen(str); i++) {
        for (int j = i + 1; j < strlen(str); j++) {
            if (str[i] == str[j]) {
                return false;
            }
        }
    }

    // If no duplicate characters encountered,
    // return true
    return true;
}

void calcul(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char* s =new char[104];
    int T;
    cin >> T;
    int c;
    int siz;
    for(int i=0;i < T;i++){
        c=0;
        cin >> s;
        siz =strlen(s);
        if(siz==1){ans[i]=1;continue;}
        for(int j=1;j <siz;j++){
            if(s[j] - s[j-1] == 1 ){
                c=1;
                break;
            }
        }
        if(c==0){
            ans[i]=0;
        }
        else{
                if(uniqueCharacters(s)){
                    ans[i]= 1;
                }
                else{ans[i]=0;}
        }

    }
    cout << "Yes" << "\n";
    for(int i=1;i<T;i++){
        if(ans[i]==1 ){
        cout << "Yes" << "\n";
        }else{
        cout << "No" << "\n";
        }

    }

}

int main(){
    calcul();

    return 0;
}


#include <bits/stdc++.h>
#define fo(i,x,y) for (int i = x; i < y; i++)
#define fd(i,x,y) for(int i = x; i>= y; i--)
#define ll long long
#define clr(A,x) memset(A, x, sizeof A)
#define pb push_back
#define mod 1000000007
#define debug(x) cout <<#x << " = " << x << endl

using namespace std;
struct datos
{
    string name;
    int region;
    int point;
} dates[100001];

bool cmp(datos a,datos b)
{
    if(a.region==b.region)
    {
        return a.point>b.point;
    }
    return a.region<b.region;
}
bool veri[100001];
pair<string,string> ans[100001];
map< pair<int,int> , int > cant;
int main ()
{
    ios::sync_with_stdio(false);
    //freopen("D:\input.txt","r",stdin);
    int n,m;
    cin>>n>>m;
    fo(i,0,n)
    {
        cin>>dates[i].name>>dates[i].region>>dates[i].point;
        veri[dates[i].region]=1;
        pair<int,int> lol;
        lol.first=dates[i].region;
        lol.second=dates[i].point;
        cant[lol]++;
    }
    sort(dates,dates+n,cmp);
    int i=0,j=0,c=1;
    while(i<n)
    {
        bool ok=0;
        int cnt=0;

        pair<string,string> hh;
        while(j<n)
        {
            //cout<<i<<" "<<j<<endl;

            if(dates[i].region!=dates[j].region)
            {
                break;
            }
            pair<int,int> lol;
            lol.first=dates[i].region;
            lol.second=dates[i].point;
            if(cant[lol]==1 && cnt==0)
            {
                hh.first=dates[j].name;
                cnt++;
            }
            else if(cant[lol]==1 && cnt==1)
            {
                cnt++;
                hh.second=dates[j].name;
                ans[dates[i].region]=hh;
            }
            j++;
        }
        if(cnt!=2)
        {
            pair<string,string> hh;
            hh.first="?",hh.second="?";
            ans[dates[i].region]=hh;
        }
        i=j;
        if(i==n)
        {
            break;
        }
    }
    fo(i,1,m+1)
    {
        if(!veri[i])
        {
            cout<<"?"<<endl;
        }
        else
        {
            if(ans[i].first=="?")
            {
                cout<<"?"<<endl;
            }
            else
            {
                cout<<ans[i].first<<" "<<ans[i].second<<endl;
            }
        }
    }
}


#include <bits/stdc++.h>
#define fo(i,x,y) for (int i = x; i < y; i++)
#define fd(i,x,y) for(int i = x; i>= y; i--)
#define ll long long
#define clr(A,x) memset(A, x, sizeof A)
#define pb push_back
#define mod 1000000007
#define debug(x) cout <<#x << " = " << x << endl

using namespace std;
struct datos
{
    string name;
    int region;
    int point;
} dates[100001];

bool cmp(datos a,datos b)
{
    if(a.region==b.region)
    {
        return a.point>b.point;
    }
    return a.region<b.region;
}
bool veri[100001];
pair<string,string> ans[100001];
int main ()
{
    ios::sync_with_stdio(false);
    //freopen("D:\input.txt","r",stdin);
    int n,m;
    cin>>n>>m;
    fo(i,0,n)
    {
        cin>>dates[i].name>>dates[i].region>>dates[i].point;
        veri[dates[i].region]=1;
    }
    sort(dates,dates+n,cmp);
    int i=0,j=1,c=1;
    while(i<n)
    {
        bool ok=0;
        while(j<n)
        {
            //cout<<i<<" "<<j<<endl;
            if(dates[i].region!=dates[j].region)
            {
                break;
            }
            if(dates[i].point!=dates[j].point)
            {
                if(!ok)
                {
                    pair<string,string> hh;
                    hh.first=dates[i].name;
                    hh.second=dates[j].name;
                    ans[dates[i].region]=hh;
                }
                ok=1;
            }
            j++;
        }
        if(!ok)
        {
            pair<string,string> hh;
            hh.first="?",hh.second="?";
            ans[dates[i].region]=hh;
        }
        i=j;
        if(i==n-1)
        {
            break;
        }
    }
    fo(i,1,m+1)
    {
        if(!veri[i])
        {
            cout<<"?"<<endl;
        }
        else
        {
            if(ans[i].first=="?")
            {
                cout<<"?"<<endl;
            }
            else
            {
                cout<<ans[i].first<<" "<<ans[i].second<<endl;
            }
        }
    }
}


#include <bits/stdc++.h>
#define fo(i,x,y) for (int i = x; i < y; i++)
#define fd(i,x,y) for(int i = x; i>= y; i--)
#define ll long long
#define clr(A,x) memset(A, x, sizeof A)
#define pb push_back
#define mod 1000000007
#define debug(x) cout <<#x << " = " << x << endl

using namespace std;
struct datos
{
    string name;
    int region;
    int point;
} dates[100009];

bool cmp(datos a,datos b)
{
    if(a.region==b.region)
    {
        return a.point>b.point;
    }
    return a.region<b.region;
}
bool veri[100001];
pair<string,string> ans[100001];
map< pair<int,int> , int > cant;
int main ()
{
    ios::sync_with_stdio(false);
    //freopen("D:\input.txt","r",stdin);
    int n,m;
    cin>>n>>m;
    fo(i,0,n)
    {
        cin>>dates[i].name>>dates[i].region>>dates[i].point;
        veri[dates[i].region]=1;
        pair<int,int> lol;
        lol.first=dates[i].region;
        lol.second=dates[i].point;
        cant[lol]++;
    }
    sort(dates,dates+n,cmp);
    int i=0,j=0,c=1;
    while(i<n)
    {
        bool ok=0;
        int cnt=0;

        while(j<n)
        {
            //cout<<i<<" "<<j<<endl;
            if(dates[i].region!=dates[j].region)
            {
                break;
            }
            if(dates[i+1].point!=dates[i+2].point && dates[i].region==dates[i+1].region)
            {
                pair<string,string> hh;
                hh.first=dates[i].name;
                hh.second=dates[i+1].name;
                ans[dates[i].region]=hh;
                ok=1;
            }
            j++;
        }
        if(!ok)
        {
            pair<string,string> hh;
            hh.first="?",hh.second="?";
            ans[dates[i].region]=hh;
        }
        i=j;
        if(i==n)
        {
            break;
        }
    }
    fo(i,1,m+1)
    {
        if(!veri[i])
        {
            cout<<"?"<<endl;
        }
        else
        {
            if(ans[i].first=="?")
            {
                cout<<"?"<<endl;
            }
            else
            {
                cout<<ans[i].first<<" "<<ans[i].second<<endl;
            }
        }
    }
}


#include <bits/stdc++.h>
#define fo(i,x,y) for (int i = x; i < y; i++)
#define fd(i,x,y) for(int i = x; i>= y; i--)
#define ll long long
#define clr(A,x) memset(A, x, sizeof A)
#define pb push_back
#define mod 1000000007
#define debug(x) cout <<#x << " = " << x << endl

using namespace std;
struct datos
{
    string name;
    int region;
    int point;
} dates[100001];

bool cmp(datos a,datos b)
{
    if(a.region==b.region)
    {
        return a.point>b.point;
    }
    return a.region<b.region;
}
bool veri[100001];
pair<string,string> ans[100001];
map< pair<int,int> , int > cant;
int main ()
{
    ios::sync_with_stdio(false);
    //freopen("D:\input.txt","r",stdin);
    int n,m;
    cin>>n>>m;
    fo(i,0,n)
    {
        cin>>dates[i].name>>dates[i].region>>dates[i].point;
        veri[dates[i].region]=1;
        pair<int,int> lol;
        lol.first=dates[i].region;
        lol.second=dates[i].point;
        cant[lol]++;
    }
    sort(dates,dates+n,cmp);
    int i=0,j=0,c=1;
    while(i<n)
    {
        bool ok=0;
        int cnt=0;

        pair<string,string> hh;
        while(j<n)
        {
            //cout<<i<<" "<<j<<endl;

            if(dates[i].region!=dates[j].region)
            {
                break;
            }
            pair<int,int> lol;
            lol.first=dates[j].region;
            lol.second=dates[j].point;
            if(cant[lol]==1 && cnt==0)
            {
                hh.first=dates[j].name;
                cnt++;
            }
            else if(cant[lol]==1 && cnt==1)
            {
                cnt++;
                hh.second=dates[j].name;
                ans[dates[i].region]=hh;
            }
            j++;
        }
        if(cnt!=2)
        {
            pair<string,string> hh;
            hh.first="?",hh.second="?";
            ans[dates[i].region]=hh;
        }
        i=j;
        if(i==n)
        {
            break;
        }
    }
    fo(i,1,m+1)
    {
        if(!veri[i])
        {
            cout<<"?"<<endl;
        }
        else
        {
            if(ans[i].first=="?")
            {
                cout<<"?"<<endl;
            }
            else
            {
                cout<<ans[i].first<<" "<<ans[i].second<<endl;
            }
        }
    }
}


#include <bits/stdc++.h>
#define fo(i,x,y) for (int i = x; i < y; i++)
#define fd(i,x,y) for(int i = x; i>= y; i--)
#define ll long long
#define clr(A,x) memset(A, x, sizeof A)
#define pb push_back
#define mod 1000000007
#define debug(x) cout <<#x << " = " << x << endl

using namespace std;
struct datos
{
    string name;
    int region;
    int point;
} dates[100009];

bool cmp(datos a,datos b)
{
    if(a.region==b.region)
    {
        return a.point>b.point;
    }
    return a.region<b.region;
}
bool veri[100001];
pair<string,string> ans[100001];
map< pair<int,int> , int > cant;
int main ()
{
    ios::sync_with_stdio(false);
    //freopen("D:\input.txt","r",stdin);
    int n,m;
    cin>>n>>m;
    fo(i,0,n)
    {
        cin>>dates[i].name>>dates[i].region>>dates[i].point;
        veri[dates[i].region]=1;
        pair<int,int> lol;
        lol.first=dates[i].region;
        lol.second=dates[i].point;
        cant[lol]++;
    }
    sort(dates,dates+n,cmp);
    int i=0,j=0,c=1;
    while(i<n)
    {
        bool ok=0;
        int cnt=0;

        while(j<n)
        {
            //cout<<i<<" "<<j<<endl;
            if(dates[i].region!=dates[j].region)
            {
                break;
            }
            if(dates[i+1].point!=dates[i+2].point && dates[i+1].region==dates[i+1].region)
            {
                pair<string,string> hh;
                hh.first=dates[i].name;
                hh.second=dates[i+1].name;
                ans[dates[i].region]=hh;
                ok=1;
            }
            j++;
        }
        if(!ok)
        {
            pair<string,string> hh;
            hh.first="?",hh.second="?";
            ans[dates[i].region]=hh;
        }
        i=j;
        if(i==n)
        {
            break;
        }
    }
    fo(i,1,m+1)
    {
        if(!veri[i])
        {
            cout<<"?"<<endl;
        }
        else
        {
            if(ans[i].first=="?")
            {
                cout<<"?"<<endl;
            }
            else
            {
                cout<<ans[i].first<<" "<<ans[i].second<<endl;
            }
        }
    }
}


#include <bits/stdc++.h>
#define sf scanf
#define pf printf

using namespace std;

struct node {

    string name ;
    int sum;
    node(){}
    node(string a , int b) { name = a ; sum = b; }
    bool operator <(const node &t) const {
        return t.sum < sum;
    }
};

vector < node > ve[10010];

int main()
{
    //freopen("input.txt" , "r" , stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(false);   cin.tie(false);
    string str;
    int n , m , id , temp ;
    cin >> n >> m;
    for(int i = 0 ; i < n ; ++i)
    {
        cin >> str >> id >> temp;
        ve[id].push_back(node(str , temp));
    }
    for(int i = 1 ; i <= m ; ++i) sort(ve[i].begin() , ve[i].end());
    int mx , cnt ;
    for(int i = 1 ; i <= m ; ++i)
    {
        if(ve[i][0].sum != ve[i][1].sum || ve[i].size() != 2) cout << "?" << endl;
        else cout << ve[i][0].name << " " << ve[i][1].name << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define sf scanf
#define pf printf

using namespace std;

struct node {

    string name ;
    int sum;
    node(){}
    node(string a , int b) { name = a ; sum = b; }
    bool operator <(const node &t) const {
        return t.sum < sum;
    }
};

vector < node > ve[10010];

int main()
{
    //freopen("input.txt" , "r" , stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(false);   cin.tie(false);
    string str;
    int n , m , id , temp ;
    cin >> n >> m;
    for(int i = 0 ; i < n ; ++i)
    {
        cin >> str >> id >> temp;
        ve[id].push_back(node(str , temp));
    }
    for(int i = 1 ; i <= m ; ++i) sort(ve[i].begin() , ve[i].end());
    int mx , cnt ;
    for(int i = 1 ; i <= m ; ++i)
    {
        if(ve[i].empty()) continue ;
        if(ve[i].size() == 2) cout << ve[i][0].name << " " << ve[i][1].name << endl;
        else
        {
            if(ve[i][1].sum == ve[i][2].sum) cout << "?" << endl;
            else cout << ve[i][0].name << " " << ve[i][1].name << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define sf scanf
#define pf printf

using namespace std;

struct node {

    string name ;
    int sum;
    node(){}
    node(string a , int b) { name = a ; sum = b; }
    bool operator <(const node &t) const {
        return t.sum < sum;
    }
};

vector < node > ve[10010];
map < int , int > mp;
map < int , int > ::iterator it , itt ;

int main()
{
    //freopen("input.txt" , "r" , stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(false);   cin.tie(false);
    string str;
    int n , m , id , temp ;
    cin >> n >> m;
    for(int i = 0 ; i < n ; ++i)
    {
        cin >> str >> id >> temp;
        ve[id].push_back(node(str , temp));
    }
    for(int i = 1 ; i <= m ; ++i) sort(ve[i].begin() , ve[i].end());
    int mx , cnt ;
    for(int i = 1 ; i <= m ; ++i)
    {
        mp.clear();
        for(int j = 0 ; j < ve[i].size() ; ++j)
        {
            mp[ve[i][j].sum]++;
        }
        it = mp.end();
        it--;
        itt = it;
        itt--;
        if(it->second >= 2 || itt->second >= 2) cout << "?" << endl;
        else cout << ve[i][0].name << " " << ve[i][1].name << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define sf scanf
#define pf printf

using namespace std;

struct node {

    string name ;
    int sum;
    node(){}
    node(string a , int b) { name = a ; sum = b; }
    bool operator <(const node &t) const {
        return t.sum < sum;
    }
};

vector < node > ve[10010];

int main()
{
    //freopen("input.txt" , "r" , stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(false);   cin.tie(false);
    string str;
    int n , m , id , temp ;
    cin >> n >> m;
    for(int i = 0 ; i < n ; ++i)
    {
        cin >> str >> id >> temp;
        ve[id].push_back(node(str , temp));
    }
    for(int i = 1 ; i <= m ; ++i) sort(ve[i].begin() , ve[i].end());
    int mx , cnt ;
    for(int i = 1 ; i <= m ; ++i)
    {
        cnt = 0;
        mx = ve[i][0].sum;
        for(int j = 0 ; j < ve[i].size() ; ++j)
        {
            if(ve[i][j].sum == mx) ++cnt;
            if(cnt >= 3) break ;
        }
        if(cnt >= 3) cout << "?" << endl;
        else cout << ve[i][0].name << " " << ve[i][1].name << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define sf scanf
#define pf printf

using namespace std;

struct node {

    string name ;
    int sum;
    node(){}
    node(string a , int b) { name = a ; sum = b; }
    bool operator <(const node &t) const {
        return t.sum < sum;
    }
};

vector < node > ve[10010];

int main()
{
    //freopen("input.txt" , "r" , stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(false);   cin.tie(false);
    string str;
    int n , m , id , temp ;
    cin >> n >> m;
    for(int i = 0 ; i < n ; ++i)
    {
        cin >> str >> id >> temp;
        ve[id].push_back(node(str , temp));
    }
    for(int i = 1 ; i <= m ; ++i) sort(ve[i].begin() , ve[i].end());
    int mx , cnt ;
    for(int i = 1 ; i <= m ; ++i)
    {
        if(ve[i].size() == 2) cout << ve[i][0].name << " " << ve[i][1].name << endl;
        else
        {
            if(ve[i][0].sum == ve[i][1].sum) cout << "?" << endl;
            else cout << ve[i][0].name << " " << ve[i][1].name << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define sf scanf
#define pf printf

using namespace std;

struct node {

    string name ;
    int sum;
    node(){}
    node(string a , int b) { name = a ; sum = b; }
    bool operator <(const node &t) const {
        return t.sum < sum;
    }
};

vector < node > ve[10010];
map < int , int > mp;
map < int , int > ::iterator it , itt ;

int main()
{
    //freopen("input.txt" , "r" , stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(false);   cin.tie(false);
    string str;
    int n , m , id , temp ;
    cin >> n >> m;
    for(int i = 0 ; i < n ; ++i)
    {
        cin >> str >> id >> temp;
        ve[id].push_back(node(str , temp));
    }
    for(int i = 1 ; i <= m ; ++i) sort(ve[i].begin() , ve[i].end());
    int mx , cnt ;
    for(int i = 1 ; i <= m ; ++i)
    {
        mp.clear();
        for(int j = 0 ; j < ve[i].size() ; ++j)
        {
            mp[ve[i][j].sum]++;
        }
        it = mp.begin();
        itt = it;
        itt++;
        if(it->second >= 2 || itt->second >= 2) cout << "?" << endl;
        else cout << ve[i][0].name << " " << ve[i][1].name << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
#define pb push_back
#define pf push_front
#define r_0 return 0
#define ld long double
using namespace std;
const ll N = 1e7;
char ch1;
ll n, m , a, b, c, x,ff;
string s1,s2;
vector<pair<ll, string>>V;
pair<ll,pair<ll,string>>p[N];
int main()
{
    cin >> n >> m;
    for( ll i =1; i <= n; i ++ )
    {
        cin >> s1 >> x >> a;
        p[i] = { x, { a, s1 } };
    }
    sort( p +1, p + 1 + n );
    for( ll i = 1; i <=m; i ++ )
    {
        V.clear();
        ff =0;
        for( ll j =1; j <= n; j ++ )
        {
            if( p[j].fr == i )
            {
                V.pb( {p[j].se.fr, p[j].se.se} );
            }
            else if( p[j].fr > i )
            {
                sort( V.begin(), V.end() );
                reverse( V.begin(), V.end() );
                if( V.size() == 2 )
                {
                    if( V[0].fr == V[1].fr )
                    {
                        cout << '?' << endl;
                    }
                    else if( V[0].fr != V[1].fr )
                    {
                        cout << V[0].se << " " << V[1].se << endl;
                    }
                }
                else
                {
                    if( V[0].fr == V[2].fr )
                    {
                        cout << '?' << endl;
                    }
                    else if( V[1].fr == V[2].fr && V[0].fr != V[1].fr )
                    {
                        cout << '?' << endl;
                    }
                    else
                    {
                        cout << V[0].se << " " << V[1].se << endl;
                    }
                }
                i++;
                j-=2;
                V.clear();
            }
        }
        break;
    }
        sort( V.begin(), V.end() );
        reverse( V.begin(), V.end() );
                if( V.size() == 2 )
                {
                    if( V[0].fr == V[1].fr )
                    {
                        cout << '?' << endl;
                    }
                    else if( V[0].fr != V[1].fr )
                    {
                        cout << V[0].se << " " << V[1].se << endl;
                    }
                }
                else
                {
                    if( V[0].fr == V[2].fr )
                    {
                        cout << '?' << endl;
                    }
                    else if( V[1].fr == V[2].fr && V[0].fr != V[1].fr )
                    {
                        cout << '?' << endl;
                    }
                    else
                    {
                        cout << V[0].se << " " << V[1].se << endl;
                    }
                }
                V.clear();
}


#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
#define pb push_back
#define pf push_front
#define r_0 return 0
#define ld long double
using namespace std;
const ll N = 1e6;
char ch1;
ll n, m , a, b, c, x,ff;
string s1,s2;
vector<pair<ll, string>>V;
pair<ll,pair<ll,string>>p[N];
int main()
{
    cin >> n >> m;
    for( ll i =1; i <= n; i ++ )
    {
        cin >> s1 >> x >> a;
        p[i] = { x, { a, s1 } };
    }
    sort( p +1, p + 1 + n );
    for( ll i = 1; i <=m; i ++ )
    {
        V.clear();
        ff =0;
        for( ll j =1; j <= n; j ++ )
        {
            if( p[j].fr == i )
            {
                V.pb( {p[j].se.fr, p[j].se.se} );
            }
            else if( p[j].fr > i )
            {
                sort( V.begin(), V.end() );
                reverse( V.begin(), V.end() );
                if( V.size() == 2 )
                {
                    if( V[0].fr == V[1].fr )
                    {
                        cout << '?' << endl;
                    }
                    else if( V[0].fr != V[1].fr )
                    {
                        cout << V[0].se << " " << V[1].se << endl;
                    }
                }
                else
                {
                    if( V[0].fr == V[2].fr )
                    {
                        cout << '?' << endl;
                    }
                    else if( V[1].fr == V[2].fr && V[0].fr != V[1].fr )
                    {
                        cout << '?' << endl;
                    }
                    else
                    {
                        cout << V[0].se << " " << V[1].se << endl;
                    }
                }
                i++;
                j-=1;
                V.clear();
            }
        }
           break;
    }
        sort( V.begin(), V.end() );
        reverse( V.begin(), V.end() );
                if( V.size() == 2 )
                {
                    if( V[0].fr == V[1].fr )
                    {
                        cout << '?' << endl;
                    }
                    else if( V[0].fr != V[1].fr )
                    {
                        cout << V[0].se << " " << V[1].se << endl;
                    }
                }
                else
                {
                    if( V[0].fr == V[2].fr )
                    {
                        cout << '?' << endl;
                    }
                    else if( V[1].fr == V[2].fr && V[0].fr != V[1].fr )
                    {
                        cout << '?' << endl;
                    }
                    else
                    {
                        cout << V[0].se << " " << V[1].se << endl;
                    }
                }
                V.clear();
}


#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
#define pb push_back
#define pf push_front
#define r_0 return 0
#define ld long double
using namespace std;
const ll N = 1e6;
char ch1;
ll n, m , a, b, c, x,ff;
string s1,s2;
vector<pair<ll, string>>V;
pair<ll,pair<ll,string>>p[N];
int main()
{
    cin >> n >> m;
    for( ll i =1; i <= n; i ++ )
    {
        cin >> s1 >> x >> a;
        p[i] = { x, { a, s1 } };
    }
    sort( p +1, p + 1 + n );
    for( ll i = 1; i <=m; i ++ )
    {
        V.clear();
        ff =0;
        for( ll j =1; j <= n; j ++ )
        {
            if( p[j].fr == i )
            {
                V.pb( {p[j].se.fr, p[j].se.se} );
            }
            else if( p[i].fr > i )
                break;
        }
        sort( V.begin(), V.end() );
        reverse( V.begin(), V.end() );
        if( V.size() == 2 )
        {
            if( V[0].fr == V[1].fr )
            {
                cout << '?' << endl;
            }
            else if( V[0].fr != V[1].fr )
            {
                cout << V[0].se << " " << V[1].se << endl;
            }
        }
        else
        {
            if( V[0].fr == V[2].fr )
            {
                cout << '?' << endl;
            }
            else if( V[1].fr == V[2].fr && V[0].fr != V[1].fr )
            {
                cout << '?' << endl;
            }
            else
            {
                cout << V[0].se << " " << V[1].se << endl;
            }
        }
        V.clear();
    }
}


#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
#define pb push_back
#define pf push_front
#define r_0 return 0
#define ld long double
using namespace std;
const ll N = 1e6 +1;
ll n, m, a, b, c,x;
string s1,s2;
pair<ll,pair<ll,string>>p[N];
vector<pair<ll,string>>V;
int main()
{
    cin >> n >> m;
    for( ll i =1; i <= n; i ++ )
    {
        cin >> s1 >> x >> a;
        p[i] = { x, {a, s1} };
    }
    c = 1;
    sort( p + 1, p + 1 + n );
    for( ll i = 1; i <= n; i ++ )
    {
        if( p[i].fr == c )
        {
            V.pb( { p[i].se.fr, p[i].se.se } );
        }
        else
        {
            sort( V.begin(), V.end() );
            reverse( V.begin(), V.end() );
            if( V.size() >= 3 && V[1].fr == V[2].fr )
                cout << '?' << endl;
            else
                cout << V[0].se << " " << V[1].se << endl;
            c++;
            V.clear();
            V.pb( { p[i].se.fr, p[i].se.se } );
        }
    }
    sort( V.begin(), V.end() );
    reverse( V.begin(), V.end() );
    if( V.size() >= 3 && V[1].fr == V[2].fr )
        cout << '?' << endl;
    else
        cout << V[0].se << " " << V[1].se << endl;
    c++;
    V.clear();
}


#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
#define pb push_back
#define pf push_front
#define r_0 return 0
#define ld long double
using namespace std;
const ll N = 1e6 +1;
ll n, m, a, b, c,x;
string s1,s2;
pair<ll,pair<ll,string>>p[N];
vector<pair<ll,string>>V;
int main()
{
    cin >> n >> m;
    for( ll i =1; i <= n; i ++ )
    {
        cin >> s1 >> x >> a;
        p[i] = { x, {a, s1} };
    }
    c = 1;
    sort( p + 1, p + 1 + n );
    for( ll i = 1; i <= n; i ++ )
    {
        if( p[i].fr == c )
        {
            V.pb( { p[i].se.fr, p[i].se.se } );
        }
        else
        {
            sort( V.begin(), V.end() );
            reverse( V.begin(), V.end() );
            if( V.size() >= 3 && V[1].fr == V[2].fr )
                cout << '?' << endl;
            else
                cout << V[0].se << " " << V[1].se << endl;
            c++;
            V.clear();
            V.pb( { p[i].se.fr, p[i].se.se } );
        }
    }
    sort( V.begin(), V.end() );
    if( V.size() >= 3 && V[1].fr == V[2].fr )
        cout << '?' << endl;
    else
        cout << V[0].se << " " << V[1].se << endl;
    c++;
    V.clear();
}


#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
#define pb push_back
#define pf push_front
#define r_0 return 0
#define ld long double
using namespace std;
const ll N = 1e6;
char ch1;
ll n, m , a, b, c, x,ff;
string s1,s2;
vector<pair<ll, string>>V;
pair<ll,pair<ll,string>>p[N];
int main()
{
    cin >> n >> m;
    for( ll i =1; i <= n; i ++ )
    {
        cin >> s1 >> x >> a;
        p[i] = { x, { a, s1 } };
    }
    sort( p +1, p + 1 + n );
    for( ll i = 1; i <=m; i ++ )
    {
        V.clear();
        ff =0;
        for( ll j =1; j <= n; j ++ )
        {
            if( p[j].fr == i )
            {
                V.pb( {p[j].se.fr, p[j].se.se} );
            }
            else if( p[j].fr > i )
            {
                sort( V.begin(), V.end() );
                reverse( V.begin(), V.end() );
                if( V.size() == 2 )
                {
                    if( V[0].fr == V[1].fr )
                    {
                        cout << '?' << endl;
                    }
                    else if( V[0].fr != V[1].fr )
                    {
                        cout << V[0].se << " " << V[1].se << endl;
                    }
                }
                else
                {
                    if( V[0].fr == V[2].fr )
                    {
                        cout << '?' << endl;
                    }
                    else if( V[1].fr == V[2].fr && V[0].fr != V[1].fr )
                    {
                        cout << '?' << endl;
                    }
                    else
                    {
                        cout << V[0].se << " " << V[1].se << endl;
                    }
                }
                i++;
                j-=2;
                V.clear();
            }
        }
        break;
    }
        sort( V.begin(), V.end() );
        reverse( V.begin(), V.end() );
                if( V.size() == 2 )
                {
                    if( V[0].fr == V[1].fr )
                    {
                        cout << '?' << endl;
                    }
                    else if( V[0].fr != V[1].fr )
                    {
                        cout << V[0].se << " " << V[1].se << endl;
                    }
                }
                else
                {
                    if( V[0].fr == V[2].fr )
                    {
                        cout << '?' << endl;
                    }
                    else if( V[1].fr == V[2].fr && V[0].fr != V[1].fr )
                    {
                        cout << '?' << endl;
                    }
                    else
                    {
                        cout << V[0].se << " " << V[1].se << endl;
                    }
                }
                V.clear();
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, string> is;
typedef pair<int, is>iis;
string a;
int b, c,cnts[100005];
int main(){
	int n, rn;
	cin >> n >> rn;
	vector<iis>v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		scanf("%d%d", &b, &c);
		v[i].first = b;
		v[i].second.second = a;
		v[i].second.first = c;
		cnts[b]++;
	}
	for (int i = 0; i < n; ++i)sort(v.begin(),v.end());
	int k = 1;
	for (int i = 0; i < n;) {
		while (!cnts[k])k++;
		if (cnts[k] == 1) {
			i++;
			printf("%s\n", v[i].second.second.c_str());
			k++;
			continue;
		}

		i += cnts[k]-2;
		if (v[i].second.first == v[i+1].second.first)puts("?");
		else printf("%s %s\n", v[i+1].second.second.c_str() ,v[i].second.second.c_str());
		i += 2;
		k++;
		if (k == rn+1)break;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, string> is;
typedef pair<int, is>iis;
string a;
int b, c,cnts[100005];
int main(){
	int n, rn;
	cin >> n >> rn;
	vector<iis>v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		scanf("%d%d", &b, &c);
		v[i].first = b;
		v[i].second.second = a;
		v[i].second.first = c;
		cnts[b]++;
	}
	for (int i = 0; i < n; ++i)sort(v.begin(),v.end());
	int k = 1;
	for (int i = 0; i < n;) {
		if (cnts[k] <= 1) {
			i += cnts[k] - 1;
			k++;
			continue;
		}
		i += cnts[k]-2;
		if (v[i].second.first == v[i+1].second.first)puts("?");
		else cout << v[i+1].second.second << ' ' << v[i].second.second<<'\n';
		i += 2;
		k++;
		if (k == rn+1)break;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, string> is;
typedef pair<int, is>iis;
string a;
int b, c,cnts[100005];
int main(){
	/*ios_base::sync_with_stdio(false);
	cin.tie(0);*/
	int n, rn;
	cin >> n >> rn;
	vector<iis>v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		scanf("%d%d", &b, &c);
		v[i].first = b;
		v[i].second.second = a;
		v[i].second.first = c;
		cnts[b]++;
	}
	sort(v.begin(),v.end());
	int k = 1;
	for (int i = 0; i < n;) {
		while (!cnts[k]) {
			cout << cnts[k] << ' ';
			puts("?");
			k++;
			if (k == rn + 1)return 0;
		}
		if (cnts[k] == 1) {
			cout << v[i].second.second << '\n';
			i++;
			k++;
			if (k == rn + 1)break;
			continue;
		}
		i += cnts[k]-2;
		if (v[i].second.first == v[i+1].second.first)puts("?");
		else cout<<v[i+1].second.second <<' '<<v[i].second.second<<'\n';
		i += 2;
		k++;
		if (k == rn+1)break;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, string> is;
typedef pair<int, is>iis;
string a;
int b, c,cnts[100005];
int main(){
	/*ios_base::sync_with_stdio(false);
	cin.tie(0);*/
	int n, rn;
	cin >> n >> rn;
	vector<iis>v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		scanf("%d%d", &b, &c);
		v[i].first = b;
		v[i].second.second = a;
		v[i].second.first = c;
		cnts[b]++;
	}
	sort(v.begin(),v.end());
	int k = 1;
	for (int i = 0; i < n;) {
		while (!cnts[k]) {
			puts("?");
			k++;
			if (k == rn + 1)return 0;
		}
		if (cnts[k] == 1) {
			cout << v[i].second.second << '\n';
			i++;
			k++;
			if (k == rn + 1)break;
			continue;
		}
		i += cnts[k]-2;
		if (v[i].second.first == v[i+1].second.first)puts("?");
		else cout<<v[i+1].second.second <<' '<<v[i].second.second<<'\n';
		i += 2;
		k++;
		if (k == rn+1)break;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, string> is;
int b, c,n,rn;
vector<is>v[10005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> rn;
	for (int i = 0; i < n; ++i) {
		string a;
		cin >> a >> b >> c;
		v[b].push_back(is(c,a));
	}
	for (int i = 1; i <= rn;++i) {
		sort(v[i].rbegin(), v[i].rend());
		if (v[i].size() <= 1)cout<<'?'<<'\n';
		else {
			if (v[i].size()>2&&v[i][1].first == v[i][2].first)cout << '?' << '\n';
			else cout << v[i][0].second << ' ' << v[i][1].second << '\n';
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, string> is;
typedef pair<int, is>iis;
string a;
int b, c,cnts[100005];
int main(){
	int n, rn;
	cin >> n >> rn;
	vector<iis>v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		scanf("%d%d", &b, &c);
		v[i].first = b;
		v[i].second.second = a;
		v[i].second.first = c;
		cnts[b]++;
	}
	for (int i = 0; i < n; ++i)sort(v.begin(),v.end());
	int k = 1;
	for (int i = 0; i < n;) {
		i += cnts[k]-2;
		if (v[i].second.first == v[i+1].second.first)puts("?");
		else cout << v[i+1].second.second << ' ' << v[i].second.second<<'\n';
		i += 2;
		k++;
		if (k == rn+1)break;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, string> is;
int b, c,n,rn;
vector<is>v[10005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> rn;
	for (int i = 0; i < n; ++i) {
		string a;
		cin >> a >> b >> c;
		v[b].push_back(is(c,a));
	}
	for (int i = 1; i <= rn;++i) {
		sort(v[i].rbegin(), v[i].rend());
		if (v[i].size() <= 1)puts("?");
		else {
			if (v[i].size()>2&&v[i][1].first == v[i][2].first)puts("?");
			else cout << v[i][0].second << ' ' << v[i][1].second << '\n';
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, string> is;
string a;
int b, c,n,rn;
vector<is>v[10005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> rn;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b >> c;
		v[b].emplace_back(c, a);
	}
	for (int i = 1; i <= rn;++i) {
		sort(v[i].rbegin(), v[i].rend());
		if (v[i].size() <= 1)puts("?");
		else {
			if (v[i][1].first == v[i][2].first)puts("?");
			else cout << v[i][0].second << ' ' << v[i][1].second << '\n';
		}
	}
}


#include <bits/stdc++.h>

using namespace std;
typedef map<string,pair<int,int> >::iterator it;
typedef map<string,int>::iterator iter;

/*
 * http://codeforces.com/problemset/problem/659/B
 */
int main(int argc, char** argv) {
	map <string,pair<int,int> > mymap;//points,region,points
	map<string,int>temp;//name,score
	int n,m; //n is number of players, m is number of regions
	int reg,poi;//region,points
	string name;//name
	int two=0;
	string blah[2];
	int again = 1;//region
	int max=0;
	int other=0;
	int c=0;

	cin>>n>>m;

	for( int i = 0; i < n; i++){
		cin >> name;
		cin>>reg;
		cin>>poi;
		mymap[name] = make_pair(reg,poi);
	}

	while(again<=m){
		int count1=0;//counter to see if there is only two from the same region
		 for(it i = mymap.begin();i!=mymap.end();i++){
			 if(i->second.first == again){
				temp[i->first] = i->second.second;
			    count1++;
			 }
		 }
		if(count1==2){
			iter loc = temp.begin();
			cout << loc->first << " ";
			loc++;
			cout << loc->first<<endl;

		 }else{
			//finds the max number and if there is greater than 2 people sharing the same number then ?
			for(iter i =temp.begin();i!=temp.end();i++){
				if(i->second > max){
					other = max;
					max = i->second;
					c=0;
				}
				else if(i->second > other && i->second != max){
					other = i->second;
				}
				if(i->second == max){
					c++;
				}
			}
			if(c>2){//three with the same highest score
				cout << "?" <<endl;
			}else{
				//used to find the 2 highest

				for(iter i = temp.begin();i!=temp.end();i++){
					if(two==2){
						break;
					}
					if(i->second == max){
						blah[0]=(i->first);
						two++;
					}
					if(i->second == other){
						blah[1]=(i->first);
						two++;
					}
				}
				cout << blah[0] << " " << blah[1] << endl;
			}
		 }
		temp.clear();
		again++;

	}
	// cout << endl;
	// for(it i = mymap.begin();i!=mymap.end();i++){
		// cout << i->first << " " << i->second.first << " " << i->second.second << endl;
	// }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef map<string,pair<int,int> >::iterator it;
typedef map<string,int>::iterator iter;

/*
 * http://codeforces.com/problemset/problem/659/B
 */
int main(int argc, char** argv) {
	map <string,pair<int,int> > mymap;//points,region,points
	map<string,int>temp;//name,score
	vector<string>names;
	int n,m; //n is number of players, m is number of regions
	int reg,poi;//region,points
	string name;//name

	cin>>n>>m;

	for( int i = 0; i < n; i++){
		cin >> name;
		cin>>reg;
		cin>>poi;
		mymap[name] = make_pair(reg,poi);
	}

	int again = 1;//region

	while(again<=m){
		int count1=0;//counter to see if there is only two from the same region
		 for(it i = mymap.begin();i!=mymap.end();i++){
			 if(i->second.first == again){
				temp[i->first] = i->second.second;
			    count1++;
			 }
		 }
		if(count1==2){
			iter loc = temp.begin();
			cout << loc->first << " ";
			loc++;
			cout << loc->first<<endl;

		 }else{
			//finds the max number and if there is greater than 2 people sharing the same number then ?
			int max=0;
			int other=0;
			int c=0;
			for(iter i =temp.begin();i!=temp.end();i++){
				if(i->second > max){
					other = max;
					max = i->second;
					c=0;
				}
				else if(i->second > other && i->second != max){
					other = i->second;
				}
				if(i->second == max){
					c++;
				}
			}
			if(c>2){//three with the same highest score
				cout << "?" <<endl;
			}else{
				//used to find the 2 highest
				int two=0;
				string blah[2];

				for(iter i = temp.begin();i!=temp.end();i++){
					if(two==2){
						break;
					}
					if(i->second == max){
						blah[0]=(i->first);
						two++;
					}
					if(i->second == other){
						blah[1]=(i->first);
						two++;
					}
				}
				cout << blah[0] << " " << blah[1] << endl;
			}
		 }
		temp.clear();
		again++;

	}
	// cout << endl;
	// for(it i = mymap.begin();i!=mymap.end();i++){
		// cout << i->first << " " << i->second.first << " " << i->second.second << endl;
	// }
    return 0;
}


/*
 * File:   main.cpp
 * Created on April 4, 2016, 1:10 PM
 */

#include <bits/stdc++.h>

using namespace std;
typedef set<pair<int,string> >::iterator it;
/*
 * http://codeforces.com/problemset/problem/659/B
 */
int main(int argc, char** argv) {
    int n;//number of players
    int m;//number of regions
    string name;// name of the player

    cin>>n;
    cin>>m;

    set<pair<int,string> > s[m]; // points, name
    int reg, pt;

    for(int i=0;i<n;i++){
        cin>>name >> reg >> pt;
        s[reg-1].insert(make_pair(800-pt,name));
    }

    for(int i=0;i<m;i++){
        it f = s[i].begin();
        if(s[i].size() < 3){
            cout<<(*f).second<<" ";
            cout<<(*(++f)).second << endl;
        }
        else{
            it two = ++f;
            it three = ++f;
            if((*two--).first == (*three--).first){
                cout << "?" << endl;
            }
            else{
                cout<<(*two).second<<" ";
                cout<<(*(three)).second << endl;
            }

        }
    }

    return 0;
}


#
#  There exist several targets which are by default empty and which can be
#  used for execution of your targets. These targets are usually executed
#  before and after some main targets. They are:
#
#     .build-pre:              called before 'build' target
#     .build-post:             called after 'build' target
#     .clean-pre:              called before 'clean' target
#     .clean-post:             called after 'clean' target
#     .clobber-pre:            called before 'clobber' target
#     .clobber-post:           called after 'clobber' target
#     .all-pre:                called before 'all' target
#     .all-post:               called after 'all' target
#     .help-pre:               called before 'help' target
#     .help-post:              called after 'help' target
#
#  Targets beginning with '.' are not intended to be called on their own.
#
#  Main targets can be executed directly, and they are:
#
#     build                    build a specific configuration
#     clean                    remove built files from a configuration
#     clobber                  remove all built files
#     all                      build all configurations
#     help                     print help mesage
#
#  Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
#  .help-impl are implemented in nbproject/makefile-impl.mk.
#
#  Available make variables:
#
#     CND_BASEDIR                base directory for relative paths
#     CND_DISTDIR                default top distribution directory (build artifacts)
#     CND_BUILDDIR               default top build directory (object files, ...)
#     CONF                       name of current configuration
#     CND_PLATFORM_${CONF}       platform name (current configuration)
#     CND_ARTIFACT_DIR_${CONF}   directory of build artifact (current configuration)
#     CND_ARTIFACT_NAME_${CONF}  name of build artifact (current configuration)
#     CND_ARTIFACT_PATH_${CONF}  path to build artifact (current configuration)
#     CND_PACKAGE_DIR_${CONF}    directory of package (current configuration)
#     CND_PACKAGE_NAME_${CONF}   name of package (current configuration)
#     CND_PACKAGE_PATH_${CONF}   path to package (current configuration)
#
# NOCDDL

# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin

# build
build: .build-post

.build-pre:
# Add your pre 'build' code here...

.build-post: .build-impl
# Add your post 'build' code here...

# clean
clean: .clean-post

.clean-pre:
# Add your pre 'clean' code here...

.clean-post: .clean-impl
# Add your post 'clean' code here...

# clobber
clobber: .clobber-post

.clobber-pre:
# Add your pre 'clobber' code here...

.clobber-post: .clobber-impl
# Add your post 'clobber' code here...

# all
all: .all-post

.all-pre:
# Add your pre 'all' code here...

.all-post: .all-impl
# Add your post 'all' code here...

# build tests
build-tests: .build-tests-post

.build-tests-pre:
# Add your pre 'build-tests' code here...

.build-tests-post: .build-tests-impl
# Add your post 'build-tests' code here...

# run tests
test: .test-post

.test-pre: build-tests
# Add your pre 'test' code here...

.test-post: .test-impl
# Add your post 'test' code here...

# help
help: .help-post

.help-pre:
# Add your pre 'help' code here...

.help-post: .help-impl
# Add your post 'help' code here...

# include project implementation makefile
include nbproject/Makefile-impl.mk

# include project make variables
include nbproject/Makefile-variables.mk


#include <bits/stdc++.h>

using namespace std;
typedef map<string,pair<int,int> >::iterator it;
typedef map<string,int>::iterator iter;

/*
 * http://codeforces.com/problemset/problem/659/B
 */
int main(int argc, char** argv) {
	map <string,pair<int,int> > mymap;//points,region,points
	map<string,int>temp;//name,score
	vector<string>names;
	int n,m; //n is number of players, m is number of regions
	cin>>n>>m;
	int reg,poi;
	string name;
	for( int i = 0; i < n; i++){
		cin >> name;
		cin>>reg;
		cin>>poi;
		mymap[name] = make_pair(reg,poi);
	}

	int again = 1;

	while(again<=m){
		// cout << again <<endl;
		int region=0;
		 for(it i = mymap.begin();i!=mymap.end();i++){
			 if(i->second.first == again){
				temp[i->first] = i->second.second;
			    region++;
			 }
		 }
		if(region==2){//works
			iter loc = temp.begin();
			cout << loc->first << " ";
			loc++;
			cout << loc->first<<endl;

		 }else{
			//finds the max number and if there is greater than 2 people sharing the same number then ?
			int max=0;
			int other=0;
			int c=0;
			for(iter i =temp.begin();i!=temp.end();i++){
				if(i->second > max){
					other = max;
					max = i->second;
					c=0;
				}
				else if(i->second > other && i->second != max){
					other = i->second;
				}

				if(i->second == max){
					c++;
				}
			}
			if(c>2){
				cout << "?" <<endl;
			}else{
				//used to find the 2 highest
				int two=0;
				string blah[2];
				for(iter i = temp.begin();i!=temp.end();i++){
					if(two==2){
						break;
					}
					if(i->second == max){
						blah[0]=(i->first);
						two++;
					}
					if(i->second == other){
						blah[1]=(i->first);
						two++;
					}
				}
				cout << blah[0] << " " << blah[1] << endl;
			}
		 }
		temp.clear();
		again++;

	}
	// cout << endl;
	// for(it i = mymap.begin();i!=mymap.end();i++){
		// cout << i->first << " " << i->second.first << " " << i->second.second << endl;
	// }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef map<string,pair<int,int> >::iterator it;
typedef map<string,int>::iterator iter;

/*
 * http://codeforces.com/problemset/problem/659/B
 */
int main(int argc, char** argv) {
	map <string,pair<int,int> > mymap;//points,region,points
	map<string,int>temp;//name,score
	vector<string>names;
	int n,m; //n is number of players, m is number of regions
	cin>>n>>m;
	int reg,poi;
	string name;
	for( int i = 0; i < n; i++){
		cin >> name;
		cin>>reg;
		cin>>poi;
		mymap[name] = make_pair(reg,poi);
	}

	int again = 1;

	while(again<=m){
		// cout << again <<endl;
		int region=0;
		 for(it i = mymap.begin();i!=mymap.end();i++){
			 if(i->second.first == again){
				temp[i->first] = i->second.second;
			    region++;
			 }
		 }
		if(region==2){//works
			iter loc = temp.begin();
			cout << loc->first << " ";
			loc++;
			cout << loc->first<<endl;

		 }else{
			//finds the max number and if there is greater than 2 people sharing the same number then ?
			int max=0;
			int other=0;
			int c=0;
			for(iter i =temp.begin();i!=temp.end();i++){
				if(i->second > max){
					other = max;
					max = i->second;
					c=0;
				}
				else if(i->second > other && i->second != max){
					other = i->second;
				}

				if(i->second == max){
					c++;
				}
			}
			if(c>2){
				cout << "?" <<endl;
			}else{
				//used to find the 2 highest
				int two=0;
				string blah[2];
				for(iter i = temp.begin();i!=temp.end();i++){
					if(two==2){
						cout <<endl;
						break;
					}
					if(i->second == max){
						blah[0]=(i->first);
						two++;
					}
					if(i->second == other){
						blah[1]=(i->first);
						two++;
					}
				}
				cout << blah[0] << " " << blah[1] << endl;
			}
		 }
		temp.clear();
		again++;

	}
	// cout << endl;
	// for(it i = mymap.begin();i!=mymap.end();i++){
		// cout << i->first << " " << i->second.first << " " << i->second.second << endl;
	// }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef map<string,pair<int,int> >::iterator it;
typedef map<string,int>::iterator iter;

/*
 * http://codeforces.com/problemset/problem/659/B
 */
int main(int argc, char** argv) {
	map <string,pair<int,int> > mymap;//points,region,points
	map<string,int>temp;//name,score

	// vector<string>names;
	int reg,poi;//region,points

	//input
	int n,m; //n is number of players, m is number of regions
	string name;//name

	cin>>n>>m;

	for( int i = 0; i < n; i++){
		cin >> name;
		cin>>reg;
		cin>>poi;
		mymap[name] = make_pair(reg,poi);
	}

	int again = 1;//region

	while(again<=m){
		int count1=0;//counter to see if there is only two from the same region
		for(it i = mymap.begin();i!=mymap.end();i++){
			if(i->second.first == again){
				temp[i->first] = i->second.second;
			    count1++;
			}
		}
		if(count1==2){
			iter loc = temp.begin();
			cout << loc->first << " ";
			loc++;
			cout << loc->first<<endl;

		 }else{
			//finds the max number and if there is greater than 2 people sharing the same number then ?
			//new test test test test
			string blah[2];

			int max=0;
			int other=0;
			int c=0;
			for(iter i =temp.begin();i!=temp.end();i++){
				if(i->second > max){
					other = max;
					blah[1] = blah[0];
					max = i->second;
					blah[0] = i->first;
					c=0;
				}
				else if(i->second > other && i->second != max){
					other = i->second;
					blah[1]=i->first;
				}
				if(i->second == max){
					c++;
				}
			}
			if(c>2){//three with the same highest score
				cout << "?" <<endl;
			}else{
				// if(temp.find(blah[0])!= temp.end()){
					// cout << temp[blah[0]] <<" ";
				// }
				// if(temp.find(blah[1])!= temp.end()){
					// cout << temp[blah[1]] << endl;
				// }
				/*
				old
				//used to find the 2 highest
				int two=0;
				string blah[2];

				for(iter i = temp.begin();i!=temp.end();i++){
					if(two==2){
						break;
					}
					if(i->second == max){
						blah[0]=(i->first);
						two++;
					}
					if(i->second == other){
						blah[1]=(i->first);
						two++;
					}
				}
				*/
				cout << blah[0] << " " << blah[1] << endl;
			}
		 }
		temp.clear();
		again++;

	}
	// cout << endl;
	// for(it i = mymap.begin();i!=mymap.end();i++){
		// cout << i->first << " " << i->second.first << " " << i->second.second << endl;
	// }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef map<string,pair<int,int> >::iterator it;
typedef map<string,int>::iterator iter;

/*
 * http://codeforces.com/problemset/problem/659/B
 */
int main(int argc, char** argv) {
	map <string,pair<int,int> > mymap;//points,region,points
	map<string,int>temp;//name,score
	vector<string>names;
	int n,m; //n is number of players, m is number of regions
	cin>>n>>m;
	int reg,poi;
	string name;
	for( int i = 0; i < n; i++){
		cin >> name;
		cin>>reg;
		cin>>poi;
		mymap[name] = make_pair(reg,poi);
	}

	int again = 1;

	while(again<=m){
		// cout << again <<endl;
		int region=0;
		 for(it i = mymap.begin();i!=mymap.end();i++){
			 if(i->second.first == again){
				temp[i->first] = i->second.second;
			    region++;
			 }
		 }
		if(region==2){//works
			iter loc = temp.begin();
			cout << loc->first << " ";
			loc++;
			cout << loc->first<<endl;

		 }else{
			//finds the max number and if there is greater than 2 people sharing the same number then ?
			int max=0;
			int other=0;
			int c=0;
			for(iter i =temp.begin();i!=temp.end();i++){
				if(i->second > max){
					other = max;
					max = i->second;
					c=0;
				}
				else if(i->second > other && i->second != max){
					other = i->second;
				}

				if(i->second == max){
					c++;
				}
			}
			cout << "max: " << max <<" "<< "other: " << other <<endl;
			if(c>2){
				cout << "?" <<endl;
			}
			//used to find the 2 highest
			int two=0;
			string blah[2];
			for(iter i = temp.begin();i!=temp.end();i++){
				if(two==2){
					cout <<endl;
					break;
				}
				if(i->second == max){
					blah[0]=(i->first);
					two++;
				}
				if(i->second == other){
					blah[1]=(i->first);
					two++;
				}
			}
			cout << blah[0] << " " << blah[1] << endl;
		 }
		temp.clear();
		again++;

	}
	// cout << endl;
	// for(it i = mymap.begin();i!=mymap.end();i++){
		// cout << i->first << " " << i->second.first << " " << i->second.second << endl;
	// }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef map<string,pair<int,int> >::iterator it;
typedef map<string,int>::iterator iter;

/*
 * http://codeforces.com/problemset/problem/659/B
 */
int main(int argc, char** argv) {
	map <string,pair<int,int> > mymap;//points,region,points
	map<string,int>temp;//name,score
	vector<string>names;
	int n,m; //n is number of players, m is number of regions
	cin>>n>>m;
	int reg,poi;
	string name;
	for( int i = 0; i < n; i++){
		cin >> name;
		cin>>reg;
		cin>>poi;
		mymap[name] = make_pair(reg,poi);
	}

	int again = 1;

	while(again<=m){
		// cout << again <<endl;
		int region=0;
		 for(it i = mymap.begin();i!=mymap.end();i++){
			 if(i->second.first == again){
				temp[i->first] = i->second.second;
			    region++;
			 }
		 }
		if(region==2){//works
			iter loc = temp.begin();
			cout << loc->first << " ";
			loc++;
			cout << loc->first<<endl;

		 }else{
			//finds the max number and if there is greater than 2 people sharing the same number then ?
			int max=0;
			int other=0;
			int c=0;
			for(iter i =temp.begin();i!=temp.end();i++){
				if(i->second > max){
					other = max;
					max = i->second;
					c=0;
				}
				else if(i->second > other && i->second != max){
					other = i->second;
				}

				if(i->second == max){
					c++;
				}
			}
			if(c>2){
				cout << "?" <<endl;
			}
			//used to find the 2 highest
			int two=0;
			string blah[2];
			for(iter i = temp.begin();i!=temp.end();i++){
				if(two==2){
					cout <<endl;
					break;
				}
				if(i->second == max){
					blah[0]=(i->first);
					two++;
				}
				if(i->second == other){
					blah[1]=(i->first);
					two++;
				}
			}
			cout << blah[0] << " " << blah[1] << endl;
		 }
		temp.clear();
		again++;

	}
	// cout << endl;
	// for(it i = mymap.begin();i!=mymap.end();i++){
		// cout << i->first << " " << i->second.first << " " << i->second.second << endl;
	// }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#if !ONLINE_JUDGE
#include "debug.h"
#else
#endif

#define INF 10001000100LL
#define MOD 1000000007

typedef long long int LL;
typedef unsigned long long LLU;
typedef long double LD;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define PP pop_back
#define LEN(vale) strlen(vale)
#define SZ(vale) (int)vale.size()
#define SQ(A) ((A)*(A))
#define pc putchar_unlocked
#define gc getchar_unlocked
#define FI(i12,fa,fb) for(i12=fa;i12<fb;++i12)
#define FD(i12,fa,fb) for(i12=fa;i12>fb;--i12)
#define FT(it,S) for(it = (S).begin(); it != (S).end(); ++it)
#define bits(vale) __builtin_popcount(vale)
#define IO  ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL)

#define SET1(array,val,sz) for(int i13=0;i13<sz;i13++)array[i13]=val;
#define SET2(array,val,sz1,sz2) for(int i13=0;i13<sz1;i13++)for(int i14=0;i14<sz2;i14++)array[i13][i14]=val;

#define ALL(a) a.begin(),a.end()
#define LB (lower_bound)
#define UB (upper_bound)

#define SI(vale) scanf("%d",&vale)
#define PI(vale) printf("%d\n",vale)
#define PIS(vale) printf("%d ",vale)
#define SL(vale) scanf("%lld",&vale)
#define PL(vale) printf("%lld\n",vale)
#define PLS(vale) printf("%lld ",vale)
#define SS(vale) scanf("%s",vale)
#define PS(vale) printf("%s\n",vale)
#define NL printf("\n")
#define PLD(vale) cout << fixed; cout.precision(12); cout << vale <<"\n"

typedef pair<int,int> PR;
typedef vector<int> vt;

#define TCS() int testcase; SI(testcase);while(testcase--)
bool deb=false;

const int N=150011;
priority_queue<pair<int,string> > pm[N];

int main(){
       //IO;
       //clock_t tStart = clock();
       int i,j,n,m;
       //TCS(){
       SI(n),SI(m);

       FI(i,0,n)
       {
              string s;
              int val;
              cin>>s>>j>>val;
              pm[j].push(MK(val,s));
       }

       FI(i,1,m+1)
       {
              vector<int> mx;
              string s1,s2;
              char aa[N]={'\0'} ,bb[N] = {'\0'};
              mx.PB(pm[i].top().F);
              s1 = pm[i].top().S;
              pm[i].pop();

              mx.PB(pm[i].top().F);
              s2 = pm[i].top().S;
              pm[i].pop();

              if((pm[i]).empty()==false)
              {
                     mx.PB(pm[i].top().F);
              }

              if(SZ(mx)>=3)
              {
                     if((mx[0] == mx[1] && mx[1] == mx[2]) || (mx[0] != mx[1] && mx[1] == mx[2]))
                            cout<<"?"<<"\n";
                     else
                     {
                            int i1;
                            FI(i1,0,SZ(s1))
                                   aa[i1] = s1[i1];
                            FI(i1,0,SZ(s2))
                                   bb[i1] = s2[i1];
                            printf("%s %s\n",aa,bb);
                     }
              }
              else
              {
                     int i1;
                     FI(i1,0,SZ(s1))
                            aa[i1] = s1[i1];
                     FI(i1,0,SZ(s2))
                            bb[i1] = s2[i1];
                     printf("%s %s\n",aa,bb);
              }
              mx.clear();
       }

       //exectime();
       return 0;
}


#include <bits/stdc++.h>
using namespace std;

#if !ONLINE_JUDGE
#include "debug.h"
#else
#endif

#define INF 10001000100LL
#define MOD 1000000007

typedef long long int LL;
typedef unsigned long long LLU;
typedef long double LD;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define PP pop_back
#define LEN(vale) strlen(vale)
#define SZ(vale) (int)vale.size()
#define SQ(A) ((A)*(A))
#define pc putchar_unlocked
#define gc getchar_unlocked
#define FI(i12,fa,fb) for(i12=fa;i12<fb;++i12)
#define FD(i12,fa,fb) for(i12=fa;i12>fb;--i12)
#define FT(it,S) for(it = (S).begin(); it != (S).end(); ++it)
#define bits(vale) __builtin_popcount(vale)
#define IO  ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL)

#define SET1(array,val,sz) for(int i13=0;i13<sz;i13++)array[i13]=val;
#define SET2(array,val,sz1,sz2) for(int i13=0;i13<sz1;i13++)for(int i14=0;i14<sz2;i14++)array[i13][i14]=val;

#define ALL(a) a.begin(),a.end()
#define LB (lower_bound)
#define UB (upper_bound)

#define SI(vale) scanf("%d",&vale)
#define PI(vale) printf("%d\n",vale)
#define PIS(vale) printf("%d ",vale)
#define SL(vale) scanf("%lld",&vale)
#define PL(vale) printf("%lld\n",vale)
#define PLS(vale) printf("%lld ",vale)
#define SS(vale) scanf("%s",vale)
#define PS(vale) printf("%s\n",vale)
#define NL printf("\n")
#define PLD(vale) cout << fixed; cout.precision(12); cout << vale <<"\n"

typedef pair<int,int> PR;
typedef vector<int> vt;

#define TCS() int testcase; SI(testcase);while(testcase--)
bool deb=false;

const int N=200011;
map<string , PR>mp;
set<pair<int,string> > st[N];

int main(){
       IO;
       //clock_t tStart = clock();
       int i,j,n,m;
       //TCS(){
       SI(n),SI(m);

       FI(i,0,n)
       {
              string s;
              int val;
              cin>>s>>j>>val;
              st[j].insert(MK(val,s));
       }

       FI(i,1,m+1)
       {
              auto it = st[i].begin();
              vector<int> mx;
              for(it = --(st[i].end()); ;it--)
              {
                     mx.PB(it->F);
                     if(SZ(mx)>=3 || it == st[i].begin())
                            break;

              }
              if(SZ(mx)>=3)
              {
                     if((mx[0] == mx[1] && mx[1] == mx[2]) || (mx[0] != mx[1] && mx[1] == mx[2]))
                            cout<<"?"<<"\n";
              }
              else
              {
                     int ct =0;
                     for(it = --(st[i].end()); ;it--)
                     {
                            cout<<it->S<<" ";
                            ct++;
                            if(ct==2 || it == st[i].begin())
                                   break;
                     }
                     cout<<"\n";
              }
              mx.clear();
       }

       //exectime();
       return 0;
}


#include <bits/stdc++.h>
using namespace std;

#if !ONLINE_JUDGE
#include "debug.h"
#else
#endif

#define INF 10001000100LL
#define MOD 1000000007

typedef long long int LL;
typedef unsigned long long LLU;
typedef long double LD;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define PP pop_back
#define LEN(vale) strlen(vale)
#define SZ(vale) (int)vale.size()
#define SQ(A) ((A)*(A))
#define pc putchar_unlocked
#define gc getchar_unlocked
#define FI(i12,fa,fb) for(i12=fa;i12<fb;++i12)
#define FD(i12,fa,fb) for(i12=fa;i12>fb;--i12)
#define FT(it,S) for(it = (S).begin(); it != (S).end(); ++it)
#define bits(vale) __builtin_popcount(vale)
#define IO  ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL)

#define SET1(array,val,sz) for(int i13=0;i13<sz;i13++)array[i13]=val;
#define SET2(array,val,sz1,sz2) for(int i13=0;i13<sz1;i13++)for(int i14=0;i14<sz2;i14++)array[i13][i14]=val;

#define ALL(a) a.begin(),a.end()
#define LB (lower_bound)
#define UB (upper_bound)

#define SI(vale) scanf("%d",&vale)
#define PI(vale) printf("%d\n",vale)
#define PIS(vale) printf("%d ",vale)
#define SL(vale) scanf("%lld",&vale)
#define PL(vale) printf("%lld\n",vale)
#define PLS(vale) printf("%lld ",vale)
#define SS(vale) scanf("%s",vale)
#define PS(vale) printf("%s\n",vale)
#define NL printf("\n")
#define PLD(vale) cout << fixed; cout.precision(12); cout << vale <<"\n"

typedef pair<int,int> PR;
typedef vector<int> vt;

#define TCS() int testcase; SI(testcase);while(testcase--)
bool deb=false;

const int N=100011;
priority_queue<pair<int,string> > pm[N];
char aa[N],bb[N];

int main(){
       //IO;
       //clock_t tStart = clock();
       int i,j,n,m;
       //TCS(){
       SI(n),SI(m);

       FI(i,0,n)
       {
              string s;
              int val;
              cin>>s>>j>>val;
              pm[j].push(MK(val,s));
       }

       FI(i,1,m+1)
       {
              vector<int> mx;
              string s1,s2;

              mx.PB(pm[i].top().F);
              s1 = pm[i].top().S;
              pm[i].pop();

              mx.PB(pm[i].top().F);
              s2 = pm[i].top().S;
              pm[i].pop();

              if((pm[i]).empty()==false)
              {
                     mx.PB(pm[i].top().F);
              }

              if(SZ(mx)>=3)
              {
                     if((mx[0] == mx[1] && mx[1] == mx[2]) || (mx[0] != mx[1] && mx[1] == mx[2]))
                            cout<<"?"<<"\n";
                     else
                     {
                            FI(i,0,SZ(s1))
                                   aa[i] = s1[i];
                            FI(i,0,SZ(s2))
                                   bb[i] = s2[i];
                            printf("%s %s\n",aa,bb);
                     }
              }
              else
              {
                            FI(i,0,SZ(s1))
                                   aa[i] = s1[i];
                            FI(i,0,SZ(s2))
                                   bb[i] = s2[i];
                            printf("%s %s\n",aa,bb);
              }
              mx.clear();
       }

       //exectime();
       return 0;
}


#include <bits/stdc++.h>
using namespace std;

#if !ONLINE_JUDGE
#include "debug.h"
#else
#endif

#define INF 10001000100LL
#define MOD 1000000007

typedef long long int LL;
typedef unsigned long long LLU;
typedef long double LD;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define PP pop_back
#define LEN(vale) strlen(vale)
#define SZ(vale) (int)vale.size()
#define SQ(A) ((A)*(A))
#define pc putchar_unlocked
#define gc getchar_unlocked
#define FI(i12,fa,fb) for(i12=fa;i12<fb;++i12)
#define FD(i12,fa,fb) for(i12=fa;i12>fb;--i12)
#define FT(it,S) for(it = (S).begin(); it != (S).end(); ++it)
#define bits(vale) __builtin_popcount(vale)
#define IO  ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL)

#define SET1(array,val,sz) for(int i13=0;i13<sz;i13++)array[i13]=val;
#define SET2(array,val,sz1,sz2) for(int i13=0;i13<sz1;i13++)for(int i14=0;i14<sz2;i14++)array[i13][i14]=val;

#define ALL(a) a.begin(),a.end()
#define LB (lower_bound)
#define UB (upper_bound)

#define SI(vale) scanf("%d",&vale)
#define PI(vale) printf("%d\n",vale)
#define PIS(vale) printf("%d ",vale)
#define SL(vale) scanf("%lld",&vale)
#define PL(vale) printf("%lld\n",vale)
#define PLS(vale) printf("%lld ",vale)
#define SS(vale) scanf("%s",vale)
#define PS(vale) printf("%s\n",vale)
#define NL printf("\n")
#define PLD(vale) cout << fixed; cout.precision(12); cout << vale <<"\n"

typedef pair<int,int> PR;
typedef vector<int> vt;

#define TCS() int testcase; SI(testcase);while(testcase--)
bool deb=false;

const int N=200011;
map<string , PR>mp;
set<pair<int,string> > st[N];

int main(){
       IO;
       //clock_t tStart = clock();
       int i,j,n,m;
       //TCS(){
       SI(n),SI(m);

       FI(i,0,n)
       {
              string s;
              int val;
              cin>>s>>j>>val;
              st[j].insert(MK(val,s));
       }

       FI(i,1,m+1)
       {
              auto it = st[i].begin();
              vector<int> mx;
              for(it = --(st[i].end()); ;it--)
              {
                     mx.PB(it->F);
                     //TR(it->F,it->S);
                     if(SZ(mx)>3 || it == st[i].begin())
                            break;

              }
              if(SZ(mx) == 2)
                     mx.PB(MOD);
              if((mx[0] == mx[1] && mx[1] == mx[2]) || (mx[0] != mx[1] && mx[1] == mx[2]))
                     cout<<"?"<<"\n";
              else
              {
                     int ct =0;
                     for(it = --(st[i].end()); ;it--)
                     {
                            cout<<it->S<<" ";
                            ct++;
                            if(ct==2 || it == st[i].begin())
                                   break;
                     }
                     cout<<"\n";
              }
       }

       //exectime();
       return 0;
}


#include <bits/stdc++.h>
using namespace std;

#if !ONLINE_JUDGE
#include "debug.h"
#else
#endif

#define INF 10001000100LL
#define MOD 1000000007

typedef long long int LL;
typedef unsigned long long LLU;
typedef long double LD;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define PP pop_back
#define LEN(vale) strlen(vale)
#define SZ(vale) (int)vale.size()
#define SQ(A) ((A)*(A))
#define pc putchar_unlocked
#define gc getchar_unlocked
#define FI(i12,fa,fb) for(i12=fa;i12<fb;++i12)
#define FD(i12,fa,fb) for(i12=fa;i12>fb;--i12)
#define FT(it,S) for(it = (S).begin(); it != (S).end(); ++it)
#define bits(vale) __builtin_popcount(vale)
#define IO  ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL)

#define SET1(array,val,sz) for(int i13=0;i13<sz;i13++)array[i13]=val;
#define SET2(array,val,sz1,sz2) for(int i13=0;i13<sz1;i13++)for(int i14=0;i14<sz2;i14++)array[i13][i14]=val;

#define ALL(a) a.begin(),a.end()
#define LB (lower_bound)
#define UB (upper_bound)

#define SI(vale) scanf("%d",&vale)
#define PI(vale) printf("%d\n",vale)
#define PIS(vale) printf("%d ",vale)
#define SL(vale) scanf("%lld",&vale)
#define PL(vale) printf("%lld\n",vale)
#define PLS(vale) printf("%lld ",vale)
#define SS(vale) scanf("%s",vale)
#define PS(vale) printf("%s\n",vale)
#define NL printf("\n")
#define PLD(vale) cout << fixed; cout.precision(12); cout << vale <<"\n"

typedef pair<int,int> PR;
typedef vector<int> vt;

#define TCS() int testcase; SI(testcase);while(testcase--)
bool deb=false;

const int N=200011;
map<string , PR>mp;
set<pair<int,string> > st[N];

int main(){
       IO;
       //clock_t tStart = clock();
       int i,j,n,m;
       //TCS(){
       SI(n),SI(m);

       FI(i,0,n)
       {
              string s;
              int val;
              cin>>s>>j>>val;
              st[j].insert(MK(val,s));
       }

       FI(i,1,m+1)
       {
              auto it = st[i].begin();
              vector<int> mx;
              int ct =0 ;
              if(SZ(st[i])>2)
                     for(it = --(st[i].end()); ;it--)
                     {
                            mx.PB(it->F);
                            if(SZ(mx)>=3 || it == st[i].begin())
                                   break;

                     }

              if(SZ(mx)>=3)
              {
                     if((mx[0] == mx[1] && mx[1] == mx[2]) || (mx[0] != mx[1] && mx[1] == mx[2]))
                            cout<<"?"<<"\n";
              }
              else
              {
                     int ct =0;
                     for(it = --(st[i].end()); ;it--)
                     {
                            cout<<it->S<<" ";
                            ct++;
                            if(ct==2 || it == st[i].begin())
                                   break;
                     }
                     cout<<"\n";
              }
              mx.clear();
       }

       //exectime();
       return 0;
}


#include <bits/stdc++.h>
using namespace std;

#if !ONLINE_JUDGE
#include "debug.h"
#else
#endif

#define INF 10001000100LL
#define MOD 1000000007

typedef long long int LL;
typedef unsigned long long LLU;
typedef long double LD;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define PP pop_back
#define LEN(vale) strlen(vale)
#define SZ(vale) (int)vale.size()
#define SQ(A) ((A)*(A))
#define pc putchar_unlocked
#define gc getchar_unlocked
#define FI(i12,fa,fb) for(i12=fa;i12<fb;++i12)
#define FD(i12,fa,fb) for(i12=fa;i12>fb;--i12)
#define FT(it,S) for(it = (S).begin(); it != (S).end(); ++it)
#define bits(vale) __builtin_popcount(vale)
#define IO  ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL)

#define SET1(array,val,sz) for(int i13=0;i13<sz;i13++)array[i13]=val;
#define SET2(array,val,sz1,sz2) for(int i13=0;i13<sz1;i13++)for(int i14=0;i14<sz2;i14++)array[i13][i14]=val;

#define ALL(a) a.begin(),a.end()
#define LB (lower_bound)
#define UB (upper_bound)

#define SI(vale) scanf("%d",&vale)
#define PI(vale) printf("%d\n",vale)
#define PIS(vale) printf("%d ",vale)
#define SL(vale) scanf("%lld",&vale)
#define PL(vale) printf("%lld\n",vale)
#define PLS(vale) printf("%lld ",vale)
#define SS(vale) scanf("%s",vale)
#define PS(vale) printf("%s\n",vale)
#define NL printf("\n")
#define PLD(vale) cout << fixed; cout.precision(12); cout << vale <<"\n"

typedef pair<int,int> PR;
typedef vector<int> vt;

#define TCS() int testcase; SI(testcase);while(testcase--)
bool deb=false;

const int N=200011;
map<string , PR>mp;
set<pair<int,string> > st[N];
priority_queue<pair<int,string> > pm[N];

int main(){
       IO;
       //clock_t tStart = clock();
       int i,j,n,m;
       //TCS(){
       SI(n),SI(m);

       FI(i,0,n)
       {
              string s;
              int val;
              cin>>s>>j>>val;
              pm[j].push(MK(val,s));
       }

       FI(i,1,m+1)
       {
              auto it = st[i].begin();
              vector<int> mx;
              string s1,s2;

              mx.PB(pm[i].top().F);
              s1 = pm[i].top().S;
              pm[i].pop();

              mx.PB(pm[i].top().F);
              s2 = pm[i].top().S;
              pm[i].pop();

              if((pm[i]).empty()==false)
              {
                     mx.PB(pm[i].top().F);
              }

              if(SZ(mx)>=3)
              {
                     if((mx[0] == mx[1] && mx[1] == mx[2]) || (mx[0] != mx[1] && mx[1] == mx[2]))
                            cout<<"?"<<"\n";
                     else
                     {
                            cout<<s1<<" "<<s2;
                            cout<<"\n";
                     }
              }
              else
              {
                     cout<<s1<<" "<<s2;
                     cout<<"\n";
              }
              mx.clear();
       }

       //exectime();
       return 0;
}


#include <bits/stdc++.h>
using namespace std;

#if !ONLINE_JUDGE
#include "debug.h"
#else
#endif

#define INF 10001000100LL
#define MOD 1000000007

typedef long long int LL;
typedef unsigned long long LLU;
typedef long double LD;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define PP pop_back
#define LEN(vale) strlen(vale)
#define SZ(vale) (int)vale.size()
#define SQ(A) ((A)*(A))
#define pc putchar_unlocked
#define gc getchar_unlocked
#define FI(i12,fa,fb) for(i12=fa;i12<fb;++i12)
#define FD(i12,fa,fb) for(i12=fa;i12>fb;--i12)
#define FT(it,S) for(it = (S).begin(); it != (S).end(); ++it)
#define bits(vale) __builtin_popcount(vale)
#define IO  ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL)

#define SET1(array,val,sz) for(int i13=0;i13<sz;i13++)array[i13]=val;
#define SET2(array,val,sz1,sz2) for(int i13=0;i13<sz1;i13++)for(int i14=0;i14<sz2;i14++)array[i13][i14]=val;

#define ALL(a) a.begin(),a.end()
#define LB (lower_bound)
#define UB (upper_bound)

#define SI(vale) scanf("%d",&vale)
#define PI(vale) printf("%d\n",vale)
#define PIS(vale) printf("%d ",vale)
#define SL(vale) scanf("%lld",&vale)
#define PL(vale) printf("%lld\n",vale)
#define PLS(vale) printf("%lld ",vale)
#define SS(vale) scanf("%s",vale)
#define PS(vale) printf("%s\n",vale)
#define NL printf("\n")
#define PLD(vale) cout << fixed; cout.precision(12); cout << vale <<"\n"

typedef pair<int,int> PR;
typedef vector<int> vt;

#define TCS() int testcase; SI(testcase);while(testcase--)
bool deb=false;

const int N=200011;
map<string , PR>mp;
set<pair<int,string> > st[N];

int main(){
       IO;
       //clock_t tStart = clock();
       int i,j,n,m;
       //TCS(){
       SI(n),SI(m);

       FI(i,0,n)
       {
              string s;
              int val;
              cin>>s>>j>>val;
              st[j].insert(MK(val,s));
       }

       FI(i,1,m+1)
       {
              auto it = st[i].begin();
              vector<int> mx;
              int ct =0 ;
              if(SZ(st[i]>2))
                     for(it = --(st[i].end()); ;it--)
                     {
                            mx.PB(it->F);
                            if(SZ(mx)>=3 || it == st[i].begin())
                                   break;

                     }

              if(SZ(mx)>=3)
              {
                     if((mx[0] == mx[1] && mx[1] == mx[2]) || (mx[0] != mx[1] && mx[1] == mx[2]))
                            cout<<"?"<<"\n";
              }
              else
              {
                     int ct =0;
                     for(it = --(st[i].end()); ;it--)
                     {
                            cout<<it->S<<" ";
                            ct++;
                            if(ct==2 || it == st[i].begin())
                                   break;
                     }
                     cout<<"\n";
              }
              mx.clear();
       }

       //exectime();
       return 0;
}


#include <bits/stdc++.h>
using namespace std;

#if !ONLINE_JUDGE
#include "debug.h"
#else
#endif

#define INF 10001000100LL
#define MOD 1000000007

typedef long long int LL;
typedef unsigned long long LLU;
typedef long double LD;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define PP pop_back
#define LEN(vale) strlen(vale)
#define SZ(vale) (int)vale.size()
#define SQ(A) ((A)*(A))
#define pc putchar_unlocked
#define gc getchar_unlocked
#define FI(i12,fa,fb) for(i12=fa;i12<fb;++i12)
#define FD(i12,fa,fb) for(i12=fa;i12>fb;--i12)
#define FT(it,S) for(it = (S).begin(); it != (S).end(); ++it)
#define bits(vale) __builtin_popcount(vale)
#define IO  ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL)

#define SET1(array,val,sz) for(int i13=0;i13<sz;i13++)array[i13]=val;
#define SET2(array,val,sz1,sz2) for(int i13=0;i13<sz1;i13++)for(int i14=0;i14<sz2;i14++)array[i13][i14]=val;

#define ALL(a) a.begin(),a.end()
#define LB (lower_bound)
#define UB (upper_bound)

#define SI(vale) scanf("%d",&vale)
#define PI(vale) printf("%d\n",vale)
#define PIS(vale) printf("%d ",vale)
#define SL(vale) scanf("%lld",&vale)
#define PL(vale) printf("%lld\n",vale)
#define PLS(vale) printf("%lld ",vale)
#define SS(vale) scanf("%s",vale)
#define PS(vale) printf("%s\n",vale)
#define NL printf("\n")
#define PLD(vale) cout << fixed; cout.precision(12); cout << vale <<"\n"

typedef pair<int,int> PR;
typedef vector<int> vt;

#define TCS() int testcase; SI(testcase);while(testcase--)
bool deb=false;

const int N=200011;
map<string , PR>mp;
set<pair<int,string> > st[N];

int main(){
       IO;
       //clock_t tStart = clock();
       int i,j,n,m;
       //TCS(){
       SI(n),SI(m);

       FI(i,0,n)
       {
              string s;
              int val;
              cin>>s>>j>>val;
              st[j].insert(MK(val,s));
       }

       FI(i,1,m+1)
       {
              auto it = st[i].begin();
              vector<int> mx;
              for(it = --(st[i].end()); ;it--)
              {
                     mx.PB(it->F);
                     if(SZ(mx)>3 || it == st[i].begin())
                            break;

              }
              if(SZ(mx)>=3)
              {
                     if((mx[0] == mx[1] && mx[1] == mx[2]) || (mx[0] != mx[1] && mx[1] == mx[2]))
                            cout<<"?"<<"\n";
              }
              else
              {
                     int ct =0;
                     for(it = --(st[i].end()); ;it--)
                     {
                            cout<<it->S<<" ";
                            ct++;
                            if(ct==2 || it == st[i].begin())
                                   break;
                     }
                     cout<<"\n";
              }
              mx.clear();
       }

       //exectime();
       return 0;
}


#include <bits/stdc++.h>
using namespace std;

#if !ONLINE_JUDGE
#include "debug.h"
#else
#endif

#define INF 10001000100LL
#define MOD 1000000007

typedef long long int LL;
typedef unsigned long long LLU;
typedef long double LD;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define PP pop_back
#define LEN(vale) strlen(vale)
#define SZ(vale) (int)vale.size()
#define SQ(A) ((A)*(A))
#define pc putchar_unlocked
#define gc getchar_unlocked
#define FI(i12,fa,fb) for(i12=fa;i12<fb;++i12)
#define FD(i12,fa,fb) for(i12=fa;i12>fb;--i12)
#define FT(it,S) for(it = (S).begin(); it != (S).end(); ++it)
#define bits(vale) __builtin_popcount(vale)
#define IO  ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL)

#define SET1(array,val,sz) for(int i13=0;i13<sz;i13++)array[i13]=val;
#define SET2(array,val,sz1,sz2) for(int i13=0;i13<sz1;i13++)for(int i14=0;i14<sz2;i14++)array[i13][i14]=val;

#define ALL(a) a.begin(),a.end()
#define LB (lower_bound)
#define UB (upper_bound)

#define SI(vale) scanf("%d",&vale)
#define PI(vale) printf("%d\n",vale)
#define PIS(vale) printf("%d ",vale)
#define SL(vale) scanf("%lld",&vale)
#define PL(vale) printf("%lld\n",vale)
#define PLS(vale) printf("%lld ",vale)
#define SS(vale) scanf("%s",vale)
#define PS(vale) printf("%s\n",vale)
#define NL printf("\n")
#define PLD(vale) cout << fixed; cout.precision(12); cout << vale <<"\n"

typedef pair<int,int> PR;
typedef vector<int> vt;

#define TCS() int testcase; SI(testcase);while(testcase--)
bool deb=false;

const int N=200011;
map<string , PR>mp;
set<pair<int,string> > st[N];

int main(){
       IO;
       //clock_t tStart = clock();
       int i,j,n,m;
       //TCS(){
       SI(n),SI(m);

       FI(i,0,n)
       {
              string s;
              int val;
              cin>>s>>j>>val;
              st[j].insert(MK(val,s));
       }

       FI(i,1,m+1)
       {
              auto it = st[i].begin();
              vector<int> mx;
              for(it = --(st[i].end()); ;it--)
              {
                     mx.PB(it->F);
                     //TR(it->F,it->S);
                     if(SZ(mx)>3 || it == st[i].begin())
                            break;

              }
              if((mx[0] == mx[1] && mx[1] == mx[2]) || (mx[0] != mx[1] && mx[1] == mx[2]))
                     cout<<"?"<<"\n";
              else
              {
                     int ct =0;
                     for(it = --(st[i].end()); ;it--)
                     {
                            cout<<it->S<<" ";
                            ct++;
                            if(ct==2 || it == st[i].begin())
                                   break;
                     }
                     cout<<"\n";
              }
       }

       //exectime();
       return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool myComparison(const pair<string,int> &a,const pair<string,int> &b)
{
       return a.second>b.second;
}
int main()
{
   ll n,m;
   while (cin>>n>>m)
   {
       vector< pair<string,int> >v[100005];
       pair<string,int>p;
       for (ll i=0;i<n;i++)
       {
           string s;
           int a,b,c;
           cin>>s>>a>>b;
           p = make_pair(s,b);
           v[a].push_back(p);
       }
       for(ll i=0;i<m;i++)
       {
           sort(v[i+1].begin(),v[i+1].end(),myComparison);
          /* for(ll j=0;j<v[i+1].size();j++)
           {
               cout<<v[i+1][j].first<<" "<<v[i+1][j].second<<endl;
           }*/

       }
       for (ll i=0;i<m;i++)
       {
           ll cnt=0;
           for (ll j=0;j<v[i+1].size();j++)
            if( v[i+1][0].second==v[i+1][j].second)
           {
               cnt++;
           }
           ll cc=0;
          for (ll j=0;j<v[i+1].size();j++)
            if( v[i+1][1].second==v[i+1][j].second)
           {
               cc++;
           }
           if (cc>=2 || cnt >1)
            cout<<"?"<<endl;
           else
           {
               p =v[i+1][0];
               pair<string,int>d;
               d=v[i+1][1];
               cout<<p.first<<" "<<d.first<<endl;
           }
           /* if (v[i+1][2].second == v[i+1][1].second)
            cout<<"?"<<endl;
           else
           {
               p =v[i+1][0];
               pair<string,int>d;
               d=v[i+1][1];
               cout<<p.first<<" "<<d.first<<endl;
           }
           */
       }
   }
}