Go: package main

import (
	"fmt"
	"sort"
)

type Datum struct {
	EraName      string
	EraBasedYear int64
	WesternYear  int64
}

const Unknown = "Unknown"

func lowerBound(data []*Datum, westernYearBorder int64) int {
	imin := -1
	imax := len(data)
	for imax-imin > 1 {
		imid := (imax + imin) / 2
		if data[imid].WesternYear >= westernYearBorder {
			imax = imid
		} else {
			imin = imid
		}
	}
	return imax
}

func solve(n, q int) {
	data := make([]*Datum, 0, n)
	for index := 0; index < n; index++ {
		datum := Datum{}
		fmt.Scan(&datum.EraName, &datum.EraBasedYear, &datum.WesternYear)
		data = append(data, &datum)
	}
	sort.Slice(data, func(i, j int) bool {
		return data[i].WesternYear < data[j].WesternYear
	})
	for cnt := 0; cnt < q; cnt++ {
		var query int64
		fmt.Scan(&query)
		var index int
		if index = lowerBound(data, query); index == n {
			fmt.Println(Unknown)
			continue
		}
		possibleDatum := data[index]
		if possibleDatum.WesternYear-query > possibleDatum.EraBasedYear-1 {
			fmt.Println(Unknown)
			continue
		}
		ans := possibleDatum.EraBasedYear - (possibleDatum.WesternYear - query)
		fmt.Println(possibleDatum.EraName, ans)
	}
}

func main() {
	for {
		var n, q int
		if fmt.Scan(&n, &q); n == 0 && q == 0 {
			break
		}
		solve(n, q)
	}
}

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

int main(){
	int N, Q;
	while(cin >> N >> Q, N+Q){
		vector<tuple<int,int,string>> t;
		for(int i = 0; i < N; ++i){
			int by, wy;
			string s;
			cin >> s >> by >> wy;
			t.push_back(make_tuple(wy,by,s));
		}
		sort(t.begin(), t.end());
		for (int i = 0; i < Q; ++i){
			int q;
			cin >> q;
			string ans = "Unknown";
			for(int j = 0; j < t.size(); ++j){
				int wy = get<0>(t[j]);
				int by = get<1>(t[j]);
				string s = get<2>(t[j]);
				if(q > wy) continue;
				if(wy-q < by){
					ans = "";
					cout << s << " " << by-(wy-q);
				}
			}
			cout << ans << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct data{
  string str;
  int era,western;
  bool operator<(const data& right)const{
    return western<right.western;
  }
};
int main(){
  int n,q,qyear,cal,flag,i,j;
  while(1){
    cin >> n >> q;
    if(n==0&&q==0) break;
    vector<data> V(n);
    for(i=0;i<n;i++) cin >> V[i].str >> V[i].era >> V[i].western;
    sort(V.begin(),V.end());
    for(i=0;i<q;i++){
      cin >> qyear;
      flag=0;
      for(j=0;j<n;j++){
	if(j==0){
	  if(qyear<=V[j].western){
	    cal=V[j].era-V[j].western+qyear;
	    if(cal>0){
	      cout << V[j].str << ' ' << cal << endl;
	    }else cout << "Unknown" << endl;
	    flag=1;
	    break;
	  }
	}else{
	  if(V[j-1].western<qyear&&qyear<=V[j].western){
	    cal=V[j].era-V[j].western+qyear;
	    if(cal>0){
	      cout << V[j].str << ' ' << cal << endl;
	    }else cout << "Unknown" << endl;
	    flag=1;
	    break;
	  }
	}
      }
      if(flag==0){
	cout << "Unknown" << endl;
      }
    }
  }
  return 0;
}

C++: #include<iostream>
#define N 1000
using namespace std;

int main(){
  while(1){
    int n,q,e[N],w[N],que[N],f;
  string str[N];
  cin>>n>>q;
  if(n+q==0) break;
  for(int i=0;i<n;i++)cin>>str[i]>>e[i]>>w[i];
    for(int i=0;i<q;i++) cin>>que[i];

    for(int i=0;i<q;i++){
      f=0;
      for(int j=0;j<n;j++)if(e[j]-(w[j]-que[i])>0 && e[j]-(w[j]-que[i])<=e[j]) cout<<str[i]<<e[i]-(w[i]-que[i])<<" "<<endl,f=1;
      if(f==0) cout<<"Unknown"<<endl;
  }
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;

int main()
{
    int n, m;

    while( cin >> n >> m )
    {
        if( n + m == 0 )
            break;

        string s[n];
        int y1[n], y2[n], y3;

        for( int i = 0; i < n; i++ )
            cin >> s[i] >> y1[i] >> y2[i];

        for( int i = 0; i < m; i++ )
        {
            cin >> y3;
            bool judge = false;
            for( int j = 0; j < n; j++ )
            {
                if( y2[j] - y3 >= 0 && y1[j] - ( y2[j] - y3 ) > 0 )
                {
                    cout << s[j] << " " << y1[j] - ( y2[j] - y3 ) << endl;
                    judge = true;
                }
            }
            if( !judge )
                cout << "Unknown" << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define era first
#define end second.first
#define str second.second
using namespace std;
typedef pair <int,pair <int,string> > P;

int main() {
  while(1){
    int n,m;
    cin >> n >> m;
    if(n==0 && m == 0) break;

    P ls[1002];

    for(int i=0;i<n;i++){
      cin >> ls[i].str >> ls[i].end >> ls[i].era;
      ls[i].era = ls[i].era-ls[i].end+1;
    }
    ls[n].era = 1000000000;
    sort(ls,ls+n);

    for(int i=0;i<m;i++){
      int a,flg = 0;
      cin >> a;
      for(int j=0;j<n;j++)
	if(ls[j].era <= a && a < ls[j+1].era){
	  if(ls[j].end >= a-ls[j].era+1) cout << ls[j].str <<" "<< a-ls[j].era+1<<endl,flg = 1;
	  break;
	}
      if(flg == 0) cout << "Unknown"<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <map>
using namespace std;
int main(void){
	int n,q;
	while(cin>>n>>q,n||q){
		map<int,string> eras;
		map<string,int> exist_year;
		int miny=-1;
		for(int i=0,eb,wy;i<n;++i){
			string nengo;
			cin>>nengo>>eb>>wy;
			eras[wy-eb]=nengo;
			if(exist_year.find(nengo)==exist_year.end()) exist_year[nengo]=wy;
			else if(exist_year[nengo]<wy) exist_year[nengo]=wy;
			if(miny==-1 || miny > wy-eb) miny=wy-eb;
		}
		for(int i=0,y;i<q;++i){
			cin>>y;
			if(miny>=y) cout<<"Unknown"<<endl;
			else{
				for(map<int,string>::reverse_iterator it=eras.rbegin();it!=eras.rend();++it){
					if(it->first < y){
						if(y<=exist_year[it->second]) cout<<it->second<<" "<<y-it->first<<endl;
						else cout<<"Unknown"<<endl;
						break;
					}
				}
			}
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct era{
  string name;
  ll ran,en;
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin>>n>>m,n+m){
    vector<era>li;
    for(int i=0;i<n;i++){
      string s;cin>>s;
      ll a,b;cin>>a>>b;
      li.pb({s,a,b});
    }
    for(int i=0;i<m;i++){
      ll year;cin>>year;
      bool fl=true;
      for(int j=0;j<n;j++){
	if(li[j].en-li[j].ran < year && year <=li[j].en){
	  fl=false;
	  cout<<li[j].name<<" "<<year-li[j].en+li[j].ran<<endl;
	  break;
	}
      }
      if(fl){cout<<"Unknown"<<endl;}
    }
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n,q;
	while(cin >> n >> q,n){
		map<string,pair<int,int> > era;
		REP(i,n){
			string s;
			int x,y;
			cin >> s >> x >> y;
			era[s] = make_pair(x,y);
		}
		REP(i,q){
			int year;
			string ans = "Unknown";
			cin >> year;
			for(auto itr = era.begin(); itr != era.end();++itr){
				if(itr->second.second >= year && itr->second.second - itr->second.first < year){
					ans = itr->first + ' ' + to_string((year - itr->second.second + itr->second.first));
				}
			}
			cout << ans << endl;
		}
	}
  return 0;
}