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 <string>
#include <iostream>
using namespace std;
int N, Q, v[1000], w[1000], x; char s[1000][20];
int main() {
	while (cin >> N >> Q, N | Q) {
		for (int i = 0; i < N; i++) scanf("%s%d%d", s[i], &v[i], &w[i]);
		for (int i = 0; i < Q; i++) {
			scanf("%d", &x); int f = 0;
			for (int j = 0; j < N; j++) {
				if (w[j] - v[j] < x && x <= w[j]) {
					printf("%d %d\n", s[j], x - w[j] + j[j]); f = 1; break;
				}
			}
			if (!f) cout << "Unknown" << endl;
		}
	}
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int N,Q;
typedef pair<unsigned int,pair<unsigned int,string> > P;
vector<P> que;
int main(){
	while(cin>>N>>Q,N||Q){
		que.clear();
		unsigned int A[1010]={0};

		for(int i = 0;i < N;i++){
			string str;
			unsigned int eray,wesy;
			cin>>str>>eray>>wesy;
			que.push_back(P(wesy,mp(eray,str)));
			A[i] = wesy;
		}
		sort(que.begin(),que.end());
		sort(A,A+N);
		for(int i = 0;i<Q;i++){
			unsigned wes;
			cin>>wes;
			int k = lower_bound(A,A+N,wes)-A;
			//cout<<que[k].first-wes<<endl;
			if(que[k].second.first>que[k].first-wes){
				cout <<que[k].second.second<<" "<<que[k].second.first-(que[k].first-wes)<<endl;
			}else{
				cout <<"Unknown"<<endl;
			}
		}
		/*(!que.empty()){
			cout <<que.top().first<<endl;
			que.pop();
		}*/
	}
	return 0;
}

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

int main() {
	int n;
	string input;
	int T = 1, N = 2, W = 3;
	int tmp;

	while(cin >> n, n != 0) {
		T = 1, N = 2, W = 3;
		for(int i = 0; i < n; i++) {
			cin >> input;

			if(input == "north") {
				tmp = N;
				N = T;
				T = 7 - tmp;
			}
			else if(input == "west") {
				tmp = W;
				W = T;
				T = 7 - tmp;
			}
			else if(input == "south") {
				tmp = T;
				T = N;
				N = 7 - tmp;
			}
			else if(input == "east") {
				tmp = T;
				T = W;
				W = 7 - tmp;
			}
			else
				exit(1);
		}

		cout << T << endl;
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
#include <iomanip>
using namespace std;

#define abs(x) ((x)>=0?(x):-(x))
#define LL long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define maxn 10000
struct node
{
  int x,y;
  int len ;
  string name;
};
node a[maxn];

int main()
{
  int n ,q ;
  
  for(int i=0;i<100000;i++)
  for(int j=0;j<100000;j++)
  for(int k=0;k<100000;k++)
  for(int l=0;l<100000;l++)
  {
      int b = 12%10;
  }
  
  while(scanf("%d%d",&n,&q)!=EOF && !(n == 0 && q == 0 ))
  {
      
    for(int i = 1; i <= n ; i ++ )
    {
      cin >> a[i].name;
      scanf("%d%d",&a[i].len ,&a[i].y);
      a[i].x = a[i].y - a[i].len + 1 ;
    }
    int x ;
    while(q --  )
    {
      scanf("%d",&x);
      int pos ;
      pos = -1 ;
      int wh;
      for(int i = 1; i <= n ; i ++ )
      {
        if(a[i].x <= x && a[i].y >= x )
        {
          pos = i ;
          wh = x - a[i].x + 1 ;
        }
      }
      if(pos == -1)
      {
        printf("Unknown\n");
      }
      else
      {
        printf("%s %d\n",a[pos].name.c_str(),wh);
      }
    }
  }
	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<a.size();i++){
			cout << a[i].ad << " ";
		}*/
		cout << endl;
		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;
}