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 <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <string>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;
typedef pair<int,int> pii;

int main () {
    int N, Q;
    while (cin >> N >> Q, N + Q) {
        vector<string> name(N);
        vector<pii> len(N);
        REP (i, 0, N) {
            cin >> name[i];
            int f, e;
            cin >> f >> e;
            len[i].first = e - f + 1;
            len[i].second = e;
        }
        REP (i, 0, Q) {
            int q;
            cin >> q;
            int cnt = 0;
            string ans = "";
            int l = 0;
            REP (j, 0, N) {
                if (len[j].first <= q && q <= len[j].second) {
                    cnt++;
                    ans = name[j];
                    l = q - len[j].first + 1;
                }
            }
            if (cnt >= 1) {
                cout << ans << ' ' << l << endl;
            } else {
                cout << "Unknown" << endl;
            }

        }
    }
    return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
template<class T> inline string toString(T x){ostringstream sout; sout<<x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);

struct data {
	int b, w;
	string n;
	data(){};
	data(int b, int w, string n) : b(b), w(w), n(n){};
};
bool operator< (const data &l, const data &r) {
	return l.w < r.w;
}

int main(){
	int N, Q;
	while(cin >> N >> Q, N) {
		vector<data> d(N);
		REP(i, N) {
			string s;
			int b, w;
			cin >> s >> b >> w;
			d[i].n = s;
			d[i].b = b;
			d[i].w = w;
		}
		sort(ALL(d));

		REP(i, Q) {
			int y;
			cin >> y;

			REP(j, N) {
				if(d[j].w-d[j].b < y && y <= d[j].w) {
					cout << d[j].n << " " << y-(d[j].w-d[j].b) << endl;
					goto next;
				}
			}
			cout << "Unknown" << endl;
			next:;
		}
	}
}

C++: #include<string>
#include<iostream>

using namespace std;

struct Era{
	string name;
	int l,r;
};

int main(){
	for(int n,q;cin>>n>>q,n;){
		Era era[1000];
		for(int i=0;i<n;i++){
			int erabased,western;
			cin>>era[i].name>>erabased>>western;
			era[i].l=western-erabased+1;
			era[i].r=western;
		}

		while(q--){
			int y;	cin>>y;
			bool found=false;
			for(int i=0;i<n;i++){
				if(era[i].l<=y && y<=era[i].r){
					cout<<era[i].name<<' '<<y-era[i].l+1<<endl;
					found=true;
					break;
				}
			}
			if(!found)	cout<<"Unknown"<<endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;

int main ()
{
    int m, n;
    while (cin >> n >> m, (n || m)) {
        map<string,P> v;
        for (int i = 0; i < n; i++) {
            string str;
            int s, e;
            cin >> str >> s >> e;
            v[str] = P(s,e);
        }

        for (int i = 0; i < m; i++) {
            int y;
            cin >> y;

            bool flag = true;
            for (auto i : v) {
                if (i.second.second - i.second.first < y && y <= i.second.second) {
                    cout << i.first << " " << y - i.second.second + i.second.first << endl;
                    flag = false;
                    break;
                }
            }
            if (flag) cout << "Unknown" << endl;
        }
    }

    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n,q;
	while(cin>>n>>q&&!(n==0&&q==0))
	{
		//各年号の元年を入れる
		pair<ll,string> a[1000];
		ll b[1000];
		REP(i,n){
			int x,y;string s;
			cin >> s>>x>>y;
			a[i]=make_pair(y-x+1,s);
			b[i]=y;
		}
		//各元号の初年度を昇順に整列
		sort(a,a+n);
		
		REP(i,q)
		{
			bool flag(false);
			ll age;cin>>age;
			
			if(age<a[0].first){cout<<"Unknown"<<endl;}
			else if(age>=a[n-1].first){cout<<a[n-1].second<<" "<<age-a[n-1].first+1<<endl;}
			else
			{
				REP(j,n-1)
				{
					if(a[j].first<=age&&a[j+1].first>age)
					{
						if(age<=b[j])
						{
							cout<<a[j].second<<" "<<age-a[j].first+1<<endl;flag=true;break;
						}
						else
						{
							cout<<"Unknown"<<endl;
						}
					}
				}
			}
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n,q;
	while(scanf("%d%d",&n,&q),n){
		map<int,string>mp;
		rep(i,n){
			string s;
			int j,k;
			cin>>s>>j>>k;
			mp[k-j]=s;
		}
		rep(i,q){
			int d;scanf("%d",&d);
			if(d<=(*mp.begin()).first){
				puts("Unknown");
				continue;
			}
			auto it=mp.rbegin();
			for(;it!=mp.rend()&&(*it).first>=d;it++);
			if(it==mp.rend())puts("Unknown");
			else cout<<(*it).second<<' '<<d-(*it).first<<endl;
		}
	}
}

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

int main(){
  while(1){
    int n,q,e[N],w[N],que,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,f=0;
      for(int j=0;j<n;j++)if(e[j]-(w[j]-que)>0 && e[j]-(w[j]-que)<=e[j]) cout<<str[j]<<" "<<e[j]-(w[j]-que)<<endl,f=1;
      if(!f) cout<<"Unknown"<<endl;
    }
  }
  return 0;
}