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 <stdio.h>
#include <string.h>

int main(void){
	int es[1000], eg[1000], 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;
		for(i = 0;i < n;i++){
			j = 0;
			while((c = getchar()) != ' ')
				name[i][j++] = c;
			name[i][j] = '\0';
			scanf("%d%d%*c",&eby,&eg[i]); // eby <= wy
			eg[i]--;
			es[i] = eg[i] - eby + 1;
		}
		for(i = 0;i < q;i++){
			scanf("%d%*c",&query);
			query--;
			for(j = 0;j < n;j++){
				if(es[j] <= query && query <= eg[j])
					break;
			}
			if(j != n)
				printf("%s %d\n",name[j],query - es[j] + 1);
			else
				printf("Unknown\n");
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n, q;
	while (cin >> n >> q, n) {
		map<int, string>mp;
		map<string, int>m;
		rep(i, n) {
			string s;
			int j, k;
			cin >> s >> j >> k;
			mp[k - j] = s;
			m[s] = j;
		}
		rep(i, q) {
			int d; cin >> d;
			auto it = mp.lower_bound(d);
			it--;
			if (it == --mp.begin()) {
				puts("Unknown");
				continue;
			}
			if (d - (*it).first > m[(*it).second]) {
				puts("Unknown");
				continue;
			}
			cout << (*it).second << ' ' << d - (*it).first << endl;
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int n,q;
	while(1){
		cin >> n >> q;
		if(n==0&&q==0) break;
		vector <string> sdata;
		vector <int> a;
		vector <int> b;
		REP(i,n){
			string tmp;
			int a1,a2;
			cin >> tmp >> a1 >> a2;
			sdata.pb(tmp);
			a.pb(a2-a1+1);
			b.pb(a2);
		}
		REP(i,q){
			int tmp;
			cin >> tmp;
			bool found = false;
			REP(j,a.size()){
				if(a[j]<=tmp&&tmp<=b[j]){
					found = true;
					cout << sdata[j] << " " << tmp-a[j]+1 << endl;
				}
			}
			if(!found) cout << "Unknown" << endl;
		}
	}
}

C++: #include<iostream>
using namespace std;
int n,q;
string s[1000];
int start[1000],len[1000];
main()
{
	while(cin>>n>>q,n)
	{
		for(int i=0;i<n;i++)
		{
			cin>>s[i]>>len[i]>>start[i];
			start[i]-=len[i]-1;
		}
		for(int i=0;i<q;i++)
		{
			int t;cin>>t;
			bool f=0;
			for(int j=0;j<n;j++)
			{
				if(start[j]<=t&&t<start[j]+len[j])
				{
					cout<<s[j]<<" "<<(t-start[j]+1)<<endl;
					f=1;
					break;
				}
			}
			if(!f)cout<<"Unknown"<<endl;
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <tuple>

using namespace std;

int main()
{
	for(int n,q;cin>>n>>q,n|q;){
		vector<tuple<string,int,int>> ys;
		for(int i=0;i<n;i++){
			string name; int year,ad;
			cin>>name>>year>>ad;
			ys.emplace_back(name,ad-year+1,ad);
		}
		
		while(q--){
			int y; cin>>y;
			int i=-1;
			for(int j=0;j<n;j++)
				if(get<1>(ys[j])<=y && y<=get<2>(ys[j])){
					i=j;
					break;
				}
			if(i==-1)
				cout<<"Unknown"<<endl;
			else
				cout<<get<0>(ys[i])<<' '<<y-get<1>(ys[i])+1<<endl;
		}
	}
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
struct era{
  ll s,e;
  string name;
  bool operator<(const era&e)const{
    return s < e.s;
  }
};
int main(){
  ll n,q;
  int i,j,k;
  era e;
  string str;
  ll b,w;
  cin >> n >> q;
  while(n+q!=0){
    vector<era> v;
    for(i=0;i<n;i++){
      cin >> str >> b >> w;
      e.name=str;
      e.s=w-b+1;e.e=w;
      //cout << e.s << " " << e.e  << endl;
      v.push_back(e);
    }
    sort(v.begin(),v.end());
    for(i=0;i<q;i++){
      cin >> b;
      ll st=0,en=v.size(),no;
      no=(st+en)/2;
      for(j=0;j<100;j++){
	if(v[no].s<=b&&b<=v[no].e) break;
	if(v[no].s<=b) st = no;
	else en=no;
	no=(st+en)/2;
      }
      //cout << v[no].s << " " << v[no].e  << endl;
      if(v[no].s<=b&&b<=v[no].e) cout << v[no].name <<" "<<  (b-v[no].s+1) << endl;
      else cout << "Unknown" << endl;
    }
    
    cin >> n >> q;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int N, Q;
    cin >> N >> Q;
    if (N == 0 && Q == 0){
      break;
    }
    vector<string> S(N);
    vector<int> E(N);
    vector<int> W(N);
    for (int i = 0; i < N; i++){
      cin >> S[i] >> E[i] >> W[i];
    }
    for (int i = 0; i < Q; i++){
      int q;
      cin >> q;
      string ans1 = "Unknown";
      int ans2 = -1;
      for (int j = 0; j < N; j++){
        if (W[j] - E[j] + 1 <= q && q <= W[j]){
          ans1 = S[j];
          ans2 = E[j] - (W[j] - q);
        }
      }
      if (ans1 == "Unknown"){
        cout << ans1 << endl;
      } else {
        cout << ans1 << ' ' << ans2 << endl;
      }
    }
  }
}

C++: #include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<iostream>

using namespace std;


int main(void) {
    while(1) {
        map<int,string> dict;
        map<string,int> max;
        int n,q;
        cin >> n >> q;
        if(!n) break;
        for(int i=0; i<n; i++) {
            string name;
            int base, west;
            cin >> name >> base >> west;
            dict[west-base+1] = name;
            max[name] = base;
        }
        for(int i=0; i<q; i++) {
            int y;
            cin >> y;
            auto it = dict.upper_bound(y);
            if(it == dict.end())
                it = dict.lower_bound(y);
            else if(it == dict.begin()) {
                cout << "Unknown" << endl;
                continue;
            }
            else
                it--;

            if((y-it->first+1) > max[it->second])
                cout << "Unknown" << endl;
            else
                cout << it->second << ' ' << y-(it->first)+1 << endl;
        }

    }
    return 0;
}