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 <bits/stdc++.h>
using namespace std;
int main(void){
    std::map<string,pair<long long int,long long int>> map;
    int n,q;
    while (cin>>n>>q) {
        if (n==0&&q==0) {
            break;
        }
        long long int era_year,western_year;
        string s;
        std::deque<string> era_name;
        std::map<string, int> seen;
        std::map<string, pair<long long int,long long int>> range;
        for (int i=0;i<n;i++) {
            cin>>s>>era_year>>western_year;
            if (seen[s]==0) {
                era_name.emplace_back(s);
                seen[s]++;
            }
            if (range[s].first==0&&range[s].second==0) {
                range[s]=make_pair(western_year-era_year+1,western_year);
            } else if (range[s].second<western_year) {
                range[s].second=western_year;
            }
        }
        long long int Q;
        for (int i=0;i<q;i++) {
            cin>>Q;
            int flag=0;
            for (int j=0;j<era_name.size();j++) {
                string era=era_name[j];
                if (range[era].first<=Q&&range[era].second>=Q) {
                    cout<<era<<" "<<Q-range[era].first+1<<endl;
                    flag=1;
                    break;
                }
            }
            if (flag==0) {
                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][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];j++);
				printf("%s %d\n",name[year[query]],j);
			}
			else
				printf("Unknown\n");
		}
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;
#define debug2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define debugg(g,h,w) rep(i,0,h) { rep(j,0,w) cout << g[i][j] << " "; cout << endl;}
#define debugv(v) for(auto&& x : v){cout << x << " ";} cout << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;
typedef pair<ll, ll> Pll;

struct era{
	string name;
	int s;
	int e;
	era(){};
	era(string _n, int _s, int _e) {name = _n, s = _s, e = _e;};
	bool operator<(const era& rhs) {
		return e < rhs.e;
	}
};
struct b {
	bool operator ()(era const& ms, int i) {
		return ms.e < i;
	}
};
era a[1010];

int main()
{
	while (1) {
		int n, q;
		cin >> n >> q;
		if (!n && !q) break;
		memset(a, 0, sizeof(a));

		rep(i,0,n) {
			string name;
			int s, e;
			cin >> name >> s >> e;
			a[i] = {name,s,e};
		}
		sort(a, a+n);
		//rep(i,0,n) cout << a[i].name << endl;

		rep(i,0,q) {
			int x;
			cin >> x;
			auto *p = lower_bound(a, a+n, x, b());
			int check = a[p-a].e - x;
			if (p-a < n && check < a[p-a].s) cout << a[p-a].name << " " << a[p-a].s-check << endl;
			else cout << "Unknown" << endl;
		}

	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){ _;
  int n,q,eby,wy,query;
  string en;
  while(cin>>n>>q,(n|q)!=0){
    map<int,pair<int,string> > era;
    REP(i,n){
      cin>>en>>eby>>wy;
      era[wy]=make_pair(eby,en);
    }
    REP(i,q){
      cin>>query;
      auto l=era.lower_bound(query);
      if(l==era.end())cout<<"Unknown"<<endl;
      else{
	int offset=query-((*l).first-(*l).second.first);
	if(offset>0){
	  cout<<(*l).second.second<<" "<<offset<<endl;
	}else{
	  cout<<"Unknown"<<endl;
	}
      }
    }
  }
}

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

using namespace std;

int main(){

    int n,q;
    string name[1001];
    int duration[1001];
    int start[1001];
    while(cin>>n>>q&&!(q==0&&n==0)){
        for(int i = 0; i < n; i++)
            cin>>name[i]>>duration[i]>>start[i];
        for(int i = 0; i < q; i++){
            int y;
            cin>>y;
            bool b=false;
            for(int j = 0; j < n; j++){
                if(start[j]>=y&&start[j]-duration[j]+1<=y){
                    cout<<name[j]<<" "<<y-start[j]+duration[j]<<endl;
                    b=true;
                    break;
                }
            }
            if(!b)
                cout<<"Unknown"<<endl;
        }
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
string S[9999],U;int n,a,b,c,d,p[9999][2],i,j;
int main(){
while(1){
cin>>a>>b;if(!a){break;}
for(i=0;i<a;i++){
n=0;cin>>U>>c>>d;
S[i]=U;
p[i][0]=d-c+1;
p[i][1]=d;
}
for(i=0;i<b;i++){
cin>>c;
for(j=0;j<a;j++){
if(c>=p[j][0] && c<=p[j][1]){
cout<<S[j]<<' '<<c-p[j][0]+1<<endl;
goto E;
}
}
printf("Unknown\n");
E:;
}
}
}

C++: #include <vector>
#include <string>
#include <iostream>
using namespace std;
int 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;i++){
			for(cin>>x,y=0;y<N;y++)if(v[y].first<x&&x<=v[y].second.first)break;
			if(y==N)cout<<"Unknown"<<endl;
			else cout<<v[y].second.second<<' '<<x-v[y].first<<endl;
		}
	}
}