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<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int N,Q;
typedef pair<unsigned int,pair<unsigned int,string> > P;
vector<P> que;
int main(){
	while(cin>>N>>Q,N||Q){
		que.clear();
		unsigned int A[1010]={0};
		for(int i = 0;i < 1010;i++){
			A[i] = 0;
		}

		for(int i = 0;i < N;i++){
			string str;
			unsigned int eray,wesy;
			cin>>str>>eray>>wesy;
			que.push_back(P(wesy,mp(eray,str)));
			A[i] = wesy;
		}
		sort(que.begin(),que.end());
		sort(A,A+N);
		for(int i = 0;i<Q;i++){
			unsigned wes;
			cin>>wes;
			bool flag =true;
			//cout<<que[k].first-wes<<endl;
			rep(j,N){
				if(wes>que[j].first-que[j].second.first&&wes<=que[j].first){
					cout <<que[j].second.second<<" "<<wes-que[j].first+que[j].second.first<<endl;
					flag = false;
					break;
				}
			}
			if(flag){
				cout <<"Unknown"<<endl;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

#define all(c) (c).begin(), (c).end()

int main(){
    int N, Q;
    while(cin >> N >> Q, N|Q){
        typedef tuple<int, int, string> Data;
        vector<Data> era;
        while(N--){
            string name;
            int eyear, wyear;
            cin >> name >> eyear >> wyear;
            era.emplace_back(wyear - eyear + 1, wyear, name);
        }
        auto comp = [](Data& d, int x){return get<1>(d) < x;};
        while(Q--){
            int query, one = 0, known = 0;
            string name;
            cin >> query;
            if(query <= get<1>(era.back()))tie(one, known, name) = *lower_bound(all(era), query, comp);
            if(one <= query && query <= known)cout << name << " " << query - one + 1 << '\n';
            else cout << "Unknown\n";
        }
    }
    return 0;
}

C++:  
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
constexpr int gcd(int a,int b){return b?gcd(b,a%b):a;}
constexpr int lcm(int a,int b){return a*b/gcd(a,b);}
 
class Eratosthenes{
  public:
    int n, sqlim;
    vector<bool> prime;
    Eratosthenes(int N):n(N+1){
        sqlim=(int)ceil(sqrt(n));
        prime=vector<bool>(n,1); prime[0]=prime[1]=0;
        for(int i=2;i<=sqlim;i++) if(prime[i]) for(int j=i*i;j<=n;j+=i) prime[j]=0;}
    vector<int> primeArray(int s=0, int l=10000){vi ret; for(int i=s;ret.size()!=l;i++) if(prime[i]) ret.push_back(i); return ret;}
};


int main(){
	int p,q;
	while(cin>>p>>q,p){
	    map<string,pii> y;
	    rep(i,p){
	        string a;int b,c;
	        cin>>a>>b>>c;
	        y[a]=mp(b,c);
	    }
        rep(i,q){
            int n;cin>>n;
            for(auto m:y){
                if(m.sc.sc-n>=0 && m.sc.sc-n<m.sc.fs){
                    cout<<m.fs<<" "<<m.sc.fs-m.sc.sc+n<<endl;
                    goto fin;
                }
            }
            cout<<"Unknown"<<endl;
            fin:;
        }
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#define MAXNUM 1000000100

int main(void){
	int year[MAXNUM], eby, wy, n, q, i, j, query;
	char name[1000][18], c;
	while(1){
		scanf("%d%d%*c",&n,&q);
		if(n == 0 && q == 0)
			break;
		memset(year,-1,sizeof(year));
		for(i = 0;i < n;i++){
			j = 0;
			while((c = getchar()) != ' ')
				name[i][j++] = c;
			name[i][j] = '\0';
			scanf("%d%d%*c",&eby,&wy); // eby <= wy
			wy--;
			for(j = 0;j < eby;j++)
				year[wy - j] = i;
		}
		for(i = 0;i < q;i++){
			scanf("%d%*c",&query);
			query--;
			if(year[query] != -1){
				for(j = 0;query - j >= 0 && year[query - j] == year[query];j++);
				printf("%s %d\n",name[year[query]],j);
			}
			else
				printf("Unknown\n");
		}
	}
	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];
		pair<ll,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]=make_pair(y-x+1,y);
		}
		//各元号の初年度を昇順に整列
		sort(a,a+n);
		sort(b,b+n);
		
		REP(i,q)
		{
			ll age;cin>>age;
			
			if(age<a[0].first)
			{
				cout<<"Unknown"<<endl;
			}
			else if(age>=a[n-1].first)
			{
				if(age<=b[n-1].second)
				{
					cout<<a[n-1].second<<" "<<age-a[n-1].first+1<<endl;
				}
				else
				{
					cout<<"Unknown"<<endl;
				}
			}
			else
			{
				REP(j,n-1)
				{
					if(a[j].first<=age&&a[j+1].first>age)
					{
						if(age<=b[j].second)
						{
							cout<<a[j].second<<" "<<age-a[j].first+1<<endl;
						}
						else
						{
							cout<<"Unknown"<<endl;
						}
					}
				}
			}
		}
	}
	return 0;
}