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 <cstring>
#include <cstdio>

using namespace std;
const int Maxn = 1010;
struct Era
{
	char name[20];
	int n;
	int year;
}era[Maxn];
int n, m;

void solve(int year)
{
	int ret = -1;
	for (int i = 0; i < n; ++i)
	{
		if (era[i].year < year) continue;
		if (era[i].year - era[i].n < year)
		{
			if (ret == -1) ret = i;
			else ret = -2;
		
		}
	}
	if (ret < 0) 
		puts("Unknown");
	else 	printf("%s %d\n", era[ret].name, era[ret].n + year - era[ret].year);
			
	
}
int main()
{
	while (scanf("%d%d", &n, &m) != EOF)
	{
		if (n == 0) break;
		for (int i = 0; i < n; ++i)
			scanf("%s%d%d", era[i].name, &era[i].n, &era[i].year);
		for (int i = 0; i < m; ++i)
		{
			int y;
			scanf("%d", &y);
			solve(y);
		}
		
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef tuple<int,int,string> T;
int main() {
	int N,Q;
	while(cin>>N>>Q,N) {
		vector<T> v;
		for(int i=0;i<N;i++) {
			string name;
			int ey,wy;
			cin>>name>>ey>>wy;
			v.push_back(make_tuple(wy-ey+1,wy,name));
		}
		sort(v.begin(),v.end());
		for(int i=0;i<Q;i++) {
			int y;
			cin>>y;
			int idx=-1;
			for(int j=0;j<v.size();j++) {
				if(get<0>(v[j])>y) break;
				if(get<0>(v[j])<=y&&y<=get<1>(v[j])) {
					idx=j;
					break;
				}
			}
			if(idx==-1) {
				cout<<"Unknown"<<endl;
			}else {
				cout<<get<2>(v[idx])<<" "<<(y-get<0>(v[idx])+1)<<endl;
			}
		}
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

int main() {
	int n, q;
	while(cin >> n >> q, n) {
		vector<string> name(n);
		vector<pair<int, int> > years(n);
		for (int i = 0; i < n; ++i) {
			cin >> name[i];
			int ey, wy; cin >> ey >> wy;
			years[i] = make_pair(wy - ey + 1, wy);
		}
		while(q--) {
			int a; cin >> a;
			bool flag = true;
			for (int j = 0; j < n; ++j) {
				if(years[j].first <= a && a<= years[j].second) {
					flag = false;
					cout << name[j] << " " << a - years[j].first + 1 << endl;
					break;
				}
			}
			if (flag) cout << "Unknown" << endl;
		}
	}

	return 0;
}

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][17], 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);
			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;year[query - j] == year[query] && query - j > 0;j++);
				printf("%s %d\n",name[year[query]],j);
			}
			else
				printf("Unknown\n");
		}
	}
	return 0;
}

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

class calender{
public:
  string s;
  int ey,wy;
  bool operator<(const calender &a)const{
    return wy < a.wy;
  }
};
int main(){
  int n,q;
  while(cin>>n>>q,n){
    calender c[1000];
    for(int i=0;i<n;i++)cin>>c[i].s>>c[i].ey>>c[i].wy;
    sort(c,c+n);
    for(int i=0;i<q;i++){
      int query;
      cin>>query;
      for(int i=0;i<n;i++){
	if(query <= c[i].wy){
	  if(c[i].wy - query < c[i].ey){
	    cout << c[i].s << " " << c[i].ey - (c[i].wy - query)<< endl;
	  }else{
	    cout << "Unknown" << endl;
	  }
	  break;
	}
      }
    }
  }
  return 0;
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2242
// ??????1000??????Eraname????????????????????????????????¶?????????????????¨?????????????????´??¨???????????¨??????????????£????????????????????´???Eraname???Key????????£??????????????´?????¢?´¢??????
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int n, q, year1, year2, query;
string name;
int main() {
    while (scanf("%d%d",&n,&q)) {
        if (n==0&&q==0) break;
        map<string, P> era;
        vector<string> names;
        for (int i=0; i<n; i++) {
            cin >> name >> year1 >> year2;
            era[name] = P(year2-year1+1, year2);
            names.push_back(name);
        }
        for (int i=0; i<q; i++) {
            scanf("%d",&query);
            for (int j=0; j<names.size(); j++) {
                P p = era[names[j]];
                if (p.first <= query && p.second >= query) {
                    cout << names[j] << " " << query-p.first+1 << endl;
                    break;
                } else if (j == names.size()-1) {
                    puts("Unknown");
                }
            }
        }
    }
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
struct R{int start;int finish;string era;};


int main(){
	struct R R1[1005];
	int N,Q;
	while(cin>>N>>Q){

		for(int i=0;i<N;i++){
			int w;
			cin>>R1[i].era>>w>>R1[i].finish;
			R1[i].start=R1[i].finish-w;
		}
		int y;
		for(int i=0;i<Q;i++){
			cin>>y;bool f=false;
			for(int j=0;j<N;j++)
			{if(R1[j].start<y&&R1[j].finish>=y){
				cout<<R1[j].era<<" "<<y-R1[j].start<<endl;
				f=true;
				break;
			}
			}
			if(f==false)cout<<"Unknown"<<endl;
			}
	}
return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

struct P {
    int x, y; string s;
    P(string &s, int x, int y) : s(s), x(x), y(y){};
};

int main() {
    int n, q;
    while(cin >> n >> q, n){
        vector<P> v;
        for (int i = 0; i < n; ++i) {
            int x, y; string s;
            cin >> s >> x >> y;
            v.emplace_back(s, y-x+1, y);
        }

        for (int i = 0; i < q; ++i) {
            int ok = 0;
            int p; cin >> p;
            for (auto &&e : v) {
                if(e.x <= p && p <= e.y){
                    cout << e.s << " " << p-e.x+1 << "\n";
                    ok = 1;
                    break;
                }
            }
            if(!ok) puts("Unknown");
        }
    }
    return 0;
}