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 <vector>
using namespace std;

struct Era{
	string name;
	int start; //0
	int end;
};

int main(){
	while(1){
		int n,q;
		cin >> n >> q;
		if(n==0) break;
		
		vector<Era> data(n);
		for(int i=0; i<n; i++){
			string name;
			int eby, wy;
			cin >> name >> eby >> wy;
			data[i].name = name;
			data[i].start = wy-eby;
			data[i].end = wy;
		}
		
		for(int i=0; i<q; i++){
			bool found = false;
			int year;
			cin >> year;
			for(int j=0; j<n; j++){
				if(data[i].start<year && year<=data[i].end){
					cout << data[i].name << " " << year-data[i].start << endl;
					found = true;
					break;
				}
			}
			if(!found){
				cout << "Unknown" << endl;
			}
		}
	}
	return 0;
}

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

using namespace std;
typedef pair<int, int> pii;
typedef pair<pii, string> piis;

int main(){
	while(true){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0){ break; }
		vector<piis> v(n);
		for(int i = 0; i < n; ++i){
			cin >> v[i].second >> v[i].first.second >> v[i].first.first;
		}
		sort(v.begin(), v.end());
		while(m--){
			int y;
			cin >> y;
			vector<piis>::iterator it =
				lower_bound(v.begin(), v.end(), piis(pii(y, 0), ""));
			if(it == v.end()){
				cout << "Unknown" << endl;
			}else{
				int jy = it->first.second - (it->first.first - y);
				if(jy <= 0){
					cout << "Unknown" << endl;
				}else{
					cout << it->second << " " << jy << endl;
				}
			}
		}
	}
	return 0;
}

C++: #include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std;



int main(){

	int n,q;
	while(cin>>n>>q,n||q){

		vector<string> era(n);
		vector<long long> a(n),b(n);

		for(int i=0;i<n;i++){
			cin>>era[i]>>a[i]>>b[i];
		}


		while(q--){
			long long y;
			cin>>y;

			
			bool ok=false;
			for(int i=0;i<n;i++){
				if( b[i]-a[i]+1<=y && y<=b[i] ){
					ok=true;
					cout<<era[i]<<" "<<y-b[i]+a[i]<<endl;
				}
			}
			
			if(!ok)cout<<"Unknown"<<endl;
		}
	}

	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
template<class T> using vv=vector< vector<T> >;
typedef deque<int> di;
typedef deque< deque<int> > ddi;


int main() {
    while(1) {
        map<string, i_i> M;
        int n,q;
        cin >> n >> q;
        if(n==0) break;
        rep(i,n) {
            string s;
            int e,w;
            cin >> s >> e >> w;
            M[s] = make_pair(w-e, max(M[s].second,e));
        } 

        rep(i,q) {
            int w;
            bool f = false;
            cin >> w;
            for(auto itr = M.begin(); itr != M.end(); ++itr) {
                if(itr->second.first < w && (itr->second.first + itr->second.second) >= w) {
                    cout << itr->first << " " << w - itr->second.first << endl;
                    f = true;
                    break;
                } 
            }
            if(!f) cout << "Unknown" << endl;
        }
    }
	return 0;
}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>

using namespace std;

#define INF 999999999

struct ye{
	string ge;
	long long int nu, ad;
	
	bool operator<(const ye& a) const{
		if(ad != a.ad) return ad < a.ad;
	}
};

int main(){
	long long int i, j, n ,q, x;
	ye ans;
	ye s;
	vector<ye> a;
	while(1){
		cin >> n >> q;
		if(!n) break;
		a.clear();
		for(i=0;i<n;i++){
			cin >> s.ge >> s.nu >> s.ad;
			a.push_back(s);
		}
		sort(a.begin(),a.end());
		for(i=0;i<q;i++){
			cin >> x;
			if(x < a[0].ad){
				if(a[0].nu - (a[0].ad - x) > 0){
					ans.ad=x;
					ans.nu=a[0].nu - (a[0].ad - x);
					ans.ge=a[0].ge;
					cout << ans.ge << " " << ans.nu << endl;
				}
				else cout << "Unknown" << endl;
			}
			else if(a[0].ad <= x && x < a[a.size()-1].ad){
				for(j=1;j<=a.size()-1;j++){
					if(a[j-1].ad == x && x == a[j].ad){
						cout << "Unknown" << endl;
					}
					else if(a[j-1].ad <= x && x < a[j].ad){
						if(a[j].nu - (a[j].ad - x) < 0){
							ans.ad=x;
							ans.nu=a[j-1].nu - (a[j-1].ad - x);
							ans.ge=a[j-1].ge;
							cout << ans.ge << " " << ans.nu << endl;
						}
						else cout << "Unknown" << endl;
					}
				}
			}
			else if(a[a.size()-1].ad <= x){
				ans.ad=x;
				ans.nu=a[a.size()-1].nu - (a[a.size()-1].ad - x);
				ans.ge=a[a.size()-1].ge;
				cout << ans.ge << " " << ans.nu << endl;
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string S[100000],U;int n,a,b,c,d,p[100000][2];
int main(){
	while(true){
		cin>>a>>b;if(a==0 && b==0){break;}
		for(int 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(int i=0;i<b;i++){
			cin>>c;
			for(int j=0;j<a;j++){
				if(c>=p[j][0] && c<=p[j][1]){
					cout<<S[i]<<' '<<c-p[i][0]+1<<endl;
					goto E;
				}
			}
			cout<<"Unknown"<<endl;
			E:;
		}
	}
}