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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int i,j,k,n,m,x,y,z,flag;
struct yea{
	int x,y;
	char num[20];
} a[10000];
char ch;
bool cmp(struct yea a,struct yea b)
{
	if (a.x<b.x) return true;
 	return false;
}


int main()
{
	
	while(1)
	{
		scanf("%d%d",&n,&m);
		if ((n==0)&&(m==0)) break;
		scanf("%c",&ch);
		for(i=0;i<n;i++)
		{
			scanf("%s%d%d",&a[i].num,&x,&y);
			a[i].x=y-x+1;
			a[i].y=y;
		}
		sort(a,a+n,cmp);
		for(i=0;i<m;i++)
		{
			scanf("%d",&x);
			flag=-1;
			for(j=0;j<n;j++)
			{
				if (a[j].x<=x && x<= a[j].y)
				{
					flag=j;
					break;
				}
				if (a[j].x>x) break;
			}
			if (flag==-1) printf("Unknown\n");
			else {
				printf("%s %d\n",a[flag].num,x-a[flag].x+1);
			}
		}
	}
	return 0;
	
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, string> TP;

int main()
{
	int N, Q, EY,WY;
	string EN;
	while (cin >> N >> Q, N || Q) {
		vector<TP> Eras(N);
		for (int i = 0; i < N; i++) {
			cin >> EN >> EY >> WY;
			get<0>(Eras[i]) = WY - EY + 1;
			get<1>(Eras[i]) = WY;
			get<2>(Eras[i]) = EN;
		}
		for (int i = 0, q; i < Q; i++) {
			cin >> q;
			auto up = upper_bound(Eras.begin(), Eras.end(), TP(q, 1000000000, string(1, 'a')));
			if (up == Eras.begin() || get<0>(*(up - 1)) > q || get<1>(*(up - 1)) < q)
				cout << "Unknown" << endl;
			else
				cout << get<2>(*(up - 1)) << ' ' << (q - get<0>(*(up - 1)) + 1) << 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[j]-(w[j]-que[i])<<endl,f=1;
      if(f==0) cout<<"Unknown"<<endl;
  }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,m,a[1000],b[1000],t;
	string s[1000];
	while(cin>>n>>m,n){
		r(i,n)cin>>s[i]>>a[i]>>b[i];
		while(m--){
			int c=0;
			cin>>t;
			r(i,n){
				if(b[i]>=t&&b[i]-a[i]<t){
					cout<<s[i]<<' '<<a[i]-(b[i]-t)<<endl;
					c++;
				}
			}
			if(!c)cout<<"Unknown"<<endl;
		}
	}
}

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

int main()
{
	while (true) {
		int N, Q;
		cin >> N >> Q;

		if (N == 0 && Q == 0) {
			break;
		}

		vector<string> names(N);
		vector<int> based(N);
		vector<int> year(N);

		for (int i = 0; i < N; i++) {
			cin >> names[i] >> based[i] >> year[i];
		}


		for (int i = 0; i < Q; i++) {
			int query;
			cin >> query;

			string ans_str;
			int ans_year = -1;

			if (query <= year[0] - based[0] || query > year[N - 1]) {
				goto End;
			}

			for (int j = 0; j < N; j++) {
				if (query > year[j]) {
					continue;
				}

				for (int k = 0; k < based[j]; k++) {
					if (year[j] - k == query) {
						ans_str = names[j];
						ans_year = based[j] - k;
						goto End;
					}
				}
			}
		End:
			if (ans_year == -1) {
				cout << "Unknown" << endl;
			}
			else {
				cout << ans_str << " " << ans_year << endl;
			}
		}
	}

	return 0;
}