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 <algorithm>
#include <vector>
using namespace std;
struct data{
  string str;
  int era,western;
  bool operator<(const data& right)const{
    return western<right.western;
  }
};
int main(){
  int n,q,qyear,cal,flag,i,j;
  while(1){
    cin >> n >> q;
    if(n==0&&q==0) break;
    vector<data> V(n);
    for(i=0;i<n;i++) cin >> V[i].str >> V[i].era >> V[i].western;
    sort(V.begin(),V.end());
    for(i=0;i<q;i++){
      cin >> qyear;
      flag=0;
      for(j=0;j<n;j++){
    if(j==0){
      if(qyear<=V[j].western){
        cal=V[j].era-V[j].western+qyear;
        if(cal>0){
          cout << V[j].str << ' ' << cal << endl;
        }else cout << "Unknown" << endl;
        flag=1;
        break;
      }
    }else{
      if(V[j-1].western<qyear&&qyear<=V[j].western){
        cal=V[j].era-V[j].western+qyear;
        if(cal>0){
          cout << V[j].str << ' ' << cal << endl;
        }else cout << "Unknown" << endl;
        flag=1;
        break;
      }
    }
      }
      if(flag==0){
    cout << "Unknown" << endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,q,y[1010],w[1010],x;
string e[1010];

int main(){
	while(cin>>n>>q&&n){
		rep(i,n)cin>>e[i]>>y[i]>>w[i];
		rep(i,q){
			cin>>x;
			int f=0;
			rep(j,n)if(w[j]-y[j]+1<=x&&x<=w[j]){
				cout<<e[j]<<" "<<y[j]-(w[j]-x)<<endl;
				f=1;
				break;
			}
			if(!f)cout<<"Unknown"<<endl;
		}
	}
}

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

using namespace std;

int N, Q;

struct Era {
	string name;
	int s, g;
};
bool operator < (const Era& e1, const Era& e2) {
	return e1.g < e2.g;
}

vector<Era> v;

void solve(int y) {
	int lb = 0, ub = N;
	while (ub - lb > 1) {
		int med = (ub + lb) / 2;
		if (v[med].s > y) ub = med;
		else lb = med;
	}
	
	if (lb == 0 && v[lb].s > y || v[lb].g < y) cout << "Unknown" << endl;
	else cout << v[lb].name << " " << y - v[lb].s + 1 << endl;
}

int main() {
	while (cin >> N >> Q, N) {
		v.clear();
		for (int i = 0; i < N; i++) {
			string name; int s, g;
			cin >> name >> s >> g;
			v.push_back((Era){name, g - s + 1, g});
		}
		sort(v.begin(), v.end());
		
		for (int i = 0; i < Q; i++) {
			int y; cin >> y;
			solve(y);
		}
	}
	
	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;
			p[i][1]=d-1;
		}
		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[j]<<' '<<c-p[j][0]+1<<endl;
					goto E;
				}
			}
			cout<<"Unknown"<<endl;
			E:;
		}
	}
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2242

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int WY[(int)1e9+10][2];
string EBY[1010];
int N, Q;

int main() {
  while (cin >> N >> Q && N) {
    fill(&WY[0][0], &WY[0][0]+((int)1e9+10)*2, 0);
    fill(EBY, EBY+1010, "");
    EBY[0] = "Unknown";
    for (int i=1; i<=N; i++) {
      string en;
      int eby, wy;
      cin >> en >> eby >> wy;
      EBY[i] = en;
      for (; eby>0; ) {
	WY[wy][0] = i;
	WY[wy][1] = eby;
	eby--;
	wy--;
      }
    }
    for (int i=0; i<Q; i++) {
      int q;
      cin >> q;
      cout << EBY[WY[q][0]]; 
      if (WY[q][0] != 0) cout << " " << WY[q][1];
      cout << endl;
    }
  }
}

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

struct Y{
  string n; int b,e;
  Y(void){}
  Y(string a,int x,int y):n(a),b(x),e(y){}
  bool operator<(const Y a)const{return b<a.b;}
};

int main(){
  int n,q,i;
  int a,b,y;
  string name;
  Y e[1010];
  std::ios::sync_with_stdio(false);
  while(cin >> n >> q, n+q){
    for(i=0;i<n;i++){
      cin >> name >> a >> b;
      e[i] = Y(name,b-a+1,b);
    }
    sort(e,e+n);
    for(i=0;i<q;i++){
      cin >> y;
      int l=-1,r=n;
      while(r-l>1){
	int m = (l+r)/2;
	if(e[m].e>=y)r = m;
	else l = m;
      }

      if(r==n || e[r].b>y)cout << "Unknown\n";
      else cout << e[r].n << " " << y-e[r].b+1 << endl;
    }
  }
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n, m;
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    vector<string> era;
    vector<int> span;
    vector<int> end;
    for (int i = 0; i < n; i++) {
      string s;
      int a, b;
      cin >> s >> a >> b;
      era.push_back(s);
      span.push_back(a);
      end.push_back(b);
    }

    for (int i = 0; i < m; i++) {
      int year;
      bool hit = false;
      cin >> year;
      for (int j = 0; j < n; j++)
        if (end[j] - span[j] <= year && year <= end[j] &&
            year - end[j] + span[j] != 0) {
          cout << era[j] << ' ' << (year - end[j] + span[j]) << endl;
          hit = true;
        break;
        }
      if (!hit)
        cout << "Unknown" << endl;
    }
    era.clear();
    span.clear();
    end.clear();
  }
  return 0;
}