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 <vector>

using namespace std;

class Era
{
public:
	string eraName;
	int eraBasedYear;
	int westernYear;
};

void solve()
{
	int N, Q;
	while(cin >> N >> Q, N || Q)
	{
		vector<Era> era(N);
		for(int i = 0; i < N; ++i)
		{
			cin >> era[i].eraName >> era[i].eraBasedYear >> era[i].westernYear;
		}
		for(int i = 0; i < Q; ++i)
		{
			int query;
			cin >> query;
			bool known = false;
			for(int j = 0; j < N; ++j)
			{
				if(era[j].westernYear - era[j].eraBasedYear + 1 <= query && query <= era[j].westernYear)
				{
					cout << era[j].eraName << " " << query - (era[j].westernYear - era[j].eraBasedYear) << endl;
					known = true;
					break;
				}
			}
			if(!known)
			{
				cout << "Unknown" << endl;
			}
		}
	}
}

int main()
{
	solve();
	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 <iostream>
#include <string>
using namespace std;
int main(){
	int n,q;
	while(cin>>n>>q){
		if(n==0&&q==0) break;
		string g[n];
		int a[n][2],b;
		for(int i=0;i<n;i++){
			cin>>g[i]>>a[i][0]>>a[i][1];
			a[i][0]=a[i][1]-a[i][0]+1;
		}
		for(int i=0;i<q;i++){
			cin>>b;
			for(int t=0;t<n;t++){
				if(b>=a[t][0]&&b<=a[t][1]){
					cout<<g[t]<<" "<<b-a[t][0]+1<<endl;
					goto end;
				}
			}
			cout<<"Unknown"<<endl;
			end:;
		}
	}
    return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[1000],b[1000],m,n,p;
  char s[1000][17];
  while(cin>>n>>m&&n&&m){
    for(i=0;i<n;i++)
      cin>>s[i]>>a[i]>>b[i];
    for(i=0;i<m;i++){
      cin>>p;
      for(j=0;j<m;j++){
	if(b[j]-a[j]<p&&p<=b[j])
	  break;
      }
      if(j==m)
	cout<<"Unknown"<<endl;
      else
	cout<<s[j]<<" "<<a[i]-b[j]+p<<endl;
    }
  }
  return 0;
}

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

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    int N, M;
    while (cin >> N >> M, N|M) {
        vector<pair<pii, string>> Q;
        REP(i, N) {
            string s;
            int era, western;
            cin >> s >> era >> western;
            Q.push_back({{western, era}, s});
            if (era > 1) {
                Q.push_back({{western-era+1, 1}, s});
            }
            Q.push_back({{western-era, 0}, s});
        }
        SORT(Q);
        REP(i, M) {
            int q;
            cin >> q;
            if (q < Q[0].first.first) {
                cout << "Unknown" << endl;
            } else if (q >= Q[SZ(Q)-1].first.first) {
                int d = q - Q[SZ(Q)-1].first.first;
                cout << Q[SZ(Q)-1].second << " " << Q[SZ(Q)-1].first.second + d << endl;
            } else {
                FOR(i, 1, SZ(Q)) {
                    if (q == Q[i-1].first.first && Q[i-1].first.second == 0) {
                        cout << "Unknown" << endl;
                        break;
                    } else if (Q[i-1].first.first <= q && q < Q[i].first.first) {
                        int d = q - Q[i-1].first.first;
                        cout << Q[i-1].second << " " << Q[i-1].first.second + d << endl;
                        break;
                    }
                }
            }
        }
    }
}