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 <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
  
using namespace std;

int main()
{
	int n, q;
	while(1){
		cin >> n >> q;
		if(n == 0 && q == 0) break;
		map<string, pair<long long int, long long int> > era;
		string inputs[1000];
		long long int by, wy;
		for(int i = 0; i < n; i++){
			cin >> inputs[i] >> by >> wy;
			era[inputs[i]] = make_pair<long long int, long long int>(wy - (by - 1), wy);
		}
		long long int query;
		for(int i = 0; i < q; i++){
			cin >> query;
			for(int j = 0; j < n; j++){
				if(era[inputs[i]].first <= query && era[inputs[i]].second >= query){
					cout << inputs[i] << " " << query - era[inputs[i]].first + 1 << endl;
					break;
				} else if(j == n - 1){
					cout << "Unknown" << endl;
				}
			}
		}
	}
	return 0;
}

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

int main()
{
	int n, q;
	while (cin >> n >> q) {
		if (n == 0)break;
		map<string,pair< int,int> > his;
		string str[1009];
		int b,c;
		string a;
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			(his[a]).first = c - b + 1; str[i] = a; (his[a]).second = c;
		}
		for (int i = 0; i < q; i++) {
			cin >> b; c = INT_MAX -100; int k;
			for (int j = 0; j < n;j++){
				if ((his[str[j]]).first <= b &&(b<=his[str[j]].second)&& (k = b - (his[str[j]]).first)+1 < c) {
					c = k; a = str[j];
				}
			}if (c == INT_MAX -100)cout << "Unknown" << endl;
			else
			cout << a <<" "<< c+1 << endl;
		}
	}
    return 0;
}

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

class era
{
	public:

		string name;
		int base,west;

		era(string n, int b, int w)
		{
			name = n;
			base = b;
			west = w;
		}

		bool operator<(const era& e) const
		{
			return (west < e.west);
		}
};

int main()
{
	int Q,N,n,b,w;
	string nm;
	//ifstream cin("A.txt");

	while(cin >> Q >> N, Q||N)
	{
		vector<era> data;
		while(Q--)
		{
			cin >> nm >> b >> w;
			data.push_back(era(nm,b,w));
		}
		sort(data.begin(), data.end());

		while(N--)
		{
			cin >> n;
			string anss;
			int ansn;
			bool ok=false;
			for(int i=0; i<data.size(); i++)
			{
				if(n-data[i].west+data[i].base>0 && n-data[i].west<=0)
				{
					ansn = n-data[i].west+data[i].base;
					anss = data[i].name;
					ok = true;
					break;
				}
			}

			if(ok)
			{
				cout << anss << " " << ansn << endl;
			}
			else
			{
				cout << "Unknown" << endl;
			}
		}
	}
}

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

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 <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);
	while(1){
		int N, Q;
		cin >> N >> Q;
		if( N == 0 && Q == 0 ) break;

		vector< string > vs;
		vector< int > st;
		vector< int > wc;
		for(int i = 0; i < N; i++) {
			string s;
			int j, k;
			cin >> s >> j >> k;
			vs.push_back( s );
			st.push_back( j );
			wc.push_back( k );
		}

		for(int i = 0; i < Q; i++) {
			int j;
			bool flg = false;
			cin >> j;
			for(int k = 0; k < N; k++) {
				if( j > wc[k] - st[k] && j <= wc[k] ) {
					cout << vs[k] << " " << j - wc[k] + st[k] << endl;
					flg = true;
					break;
				}
			}
			if( flg == false )
				cout << "Unknown" << endl;
		}

 	}

	//while(1){}
    return 0;
}

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;

			int ans_year = -1;
			string ans_name;

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

				int temp = based[j] - (year[j] - query);

				if (temp < 1) {
					continue;
				}
				else {
					ans_name = names[j];
					ans_year = temp;
					break;
				}
			}

			if (ans_year == -1) {
				cout << "Unknown" << endl;
			}
			else {
				cout << ans_name << " " << ans_year << endl;
			}
		}
	}

	return 0;
}

C++: #include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int N, Q;

    while (cin >> N >> Q, N || Q) {
        vector<pair<int, string> > memo;

        for (int i = 0; i < N; i++) {
            string s;
            int ey, wy;

            cin >> s >> ey >> wy;
            memo.push_back(make_pair(wy - ey, s));
        }
        sort(memo.begin(), memo.end());


        for (int i = 0; i < Q; i++) {
            int q;

            cin >> q;
            bool flag = false;
            for (int j = 0; j < N - 1; j++) {
                if (memo[j].first <= q && memo[j + 1].first > q) {
                    flag = true;
                    cout << memo[j].second << " " << q - memo[j].first << endl;
                    break;
                }
            }

            if (!flag)
                cout << "Unknown" << endl;
        }
    }

    return 0;
}