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<string>
#include<map>
using namespace std;
int main()
{
  while(true){
    int N,Q;
    cin >> N >> Q;
    if(N==0&&Q==0)break;
    map<int,string> M;
    for(int i = 0; i < N; ++i){
      string era;
      int now;
      int y;
      cin >> era >> now >> y;
      M[y-now+1]=era;
      M[y]=era;
    }
    for(int i = 0; i < Q; ++i){
      int y;
      int res=-1;
      string res_era;
      cin >> y;
      map<int,string>::iterator itm = M.lower_bound(y);
      if(itm!=M.begin()){
	--itm;
      }
      while(true){
	if(itm->first>y){
	  break;
	}else{
	  map<int,string>::iterator itm2 = itm;
	  itm2++;
	  if(itm2==M.end())break;
	  if( y >= itm->first && itm->second == itm2->second ){
	    res = y - itm->first + 1;
	    res_era = itm->second;
	  }
	}
	++itm;
      }
      if(res>0){
	cout << res_era << ' ' << res << endl;
      }else{
	cout << "Unknown" << endl;
      }
    }
  }
  return 0;
}

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

using namespace std;
typedef pair<int, string> P;

void solve()
{
	int N, Q;
	while(cin >> N >> Q, N || Q)
	{
		vector<P> Vec(N);
		for(int i = 0; i < N; ++i)
		{
			string str;
			int a, b;
			cin >> str >> a >> b;
			Vec[i].first = b - a;
			Vec[i].second = str;
		}
		sort(Vec.begin(), Vec.end());
		for(int i = 0; i < Q; ++i)
		{
			int year;
			cin >> year;
			int pos = 0;
			while(year > Vec[pos].first)
			{
				++pos;
				if(pos == N || year == Vec[pos].first)
				{
					cout << "Unknown" << endl;
					goto NEXT;
				}
			}
			if(pos != 0)
			{
				cout << Vec[pos - 1].second << " " << year - Vec[pos - 1].first << endl;
			}
			else
			{
				cout << "Unknown" << endl;
			}
NEXT:
			;
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

#include<string>
#include<map>
using namespace std;

int main(){
  int N,Q;
  string eraname;
  int basedy,westy;
  while(cin >> N >> Q && (N!=0 || Q!=0)){
    string nams[10010];
    int begin[N],end[N];
    for(int i=0;i<N;i++){
      cin >> eraname >> basedy >> westy;
      nams[i]=eraname;
      begin[i]=westy-basedy;
      end[i]=westy;
    }
    for(int i=0;i<Q;i++){
      cin >> westy;
      for(int j=0;j<N;j++){
	if(westy > begin[j] && westy <=end[j]){
	  cout << nams[j] << ' ' << westy-begin[j] <<endl;
	  break;
	}
	if(j==N-1){
	  cout << "Unknown" << endl;
	}
      }
    }
  }

}

C++: //#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define fo(x,a,b) for(register int x=a;x<=b;x++)
#define dfo(x,a,b) for(register int x=a;x>b;x--)
#define inf 2147483647
using namespace std;
int a[1005][2],n,m,x,y;
char ch[1005][20];
int main ()
{
	//freopen("timename.in","r",stdin);
	//freopen("timename.out","w",stdout);
	while (true)
	{
		scanf("%d%d\n",&n,&m);
		if (n==0&&m==0) break;
		fo(ii,1,n)
			fo(j,1,16)
				ch[ii][j]='\000';
		fo(ii,1,n)
		{
			int i=0;
			while((ch[ii][++i]=getchar())!=' ');
			ch[ii][i]='\000';
			scanf("%d%d\n",&x,&y);
			a[ii][1]=y;
			a[ii][0]=y-x+1;
		}
		fo(ii,1,m)
		{
			scanf("%d\n",&y);
			bool pd=false;
			fo(i,1,n)
			{
				if(a[i][1]>=y&&a[i][0]<=y){printf("%s %d\n",ch[i]+1,y-a[i][0]+1);pd=true;break;}
			}
			if (pd==false) printf("Unknown\n");
		}
	}

	return 0;
}

C++: #include <vector>
#include <string>
#include <iostream>
using namespace std;
main(){int N,Q,i,x,y;string s;for(;cin>>N>>Q,N;){
	vector<pair<int,pair<int,string> > >v;
	for(i=0;i<N;i++)cin>>s>>x>>y,v.push_back(make_pair(y-x,make_pair(y,s)));
	for(i=0;i<Q;y<N?cout<<v[y].second.second<<' '<<x-v[y].first<<endl:cout<<"Unknown"<<endl,i++)for(cin>>x,y=0;y<N;y++)if(v[y].first<x&&x<=v[y].second.first)break;
}}

C++: #include<iostream>
#include<cstdio>
#include<map>
using namespace std;
struct nian
{
    char name[20];
    int l,r;
}year[1005];
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        if(n==0&&m==0) break;
        for(int i=0;i<n;i++)
        {
            scanf("%s %d %d",year[i].name,&year[i].l,&year[i].r);
            year[i].l=year[i].r-year[i].l+1;
        }
        while(m--)
        {
            int tmp,k=-1,flag;
            scanf("%d",&tmp);
            for(int i=0;i<n;i++)
            {
                if(tmp>=year[i].l&&tmp<=year[i].r)
                {
                    flag=i;
                    k=tmp-year[i].l+1;
                    break;
                }
            }
            if(k==-1) puts("Unknown");
            else
            {
                printf("%s %d\n",year[flag].name,k);
            }
        }
    }
    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);
			auto it = mp.lower_bound(d);
			it--;
			if (it == --mp.begin()) {
				puts("Unknown");
				continue;
			}
			if ((*it).first == d) {
				puts("Unknown");
				continue;
			}
			if (it != --mp.end()) {
				if ((*++it).first - d == -1) {
					puts("Unknown");
					continue;
				}
				else it--;
			}
			cout << (*it).second << ' ' << d - (*it).first << endl;
		}
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;


const int dx[]={0,0,-1,1};
const int dy[]={-1,1,0,0};

int main()
{
	int n,q;
	while(cin>>n>>q,n||q){
		vector<string> name(n);
		vector<long long> a(n),b(n);

		for(int i=0;i<n;i++) cin>>name[i]>>a[i]>>b[i];

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

			bool unknown=true;

			for(int i=0;i<n && unknown;i++){
				if(b[i]-a[i]+1<=y && y<=b[i]){
					unknown=false;
					cout<<name[i]<<" "<<y-b[i]+a[i]<<endl;
				}
			}

			if(unknown) cout<<"Unknown"<<endl;

		}

	}

	return 0;
}