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>
//#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000			 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979
#define MAXI 7500000

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<double, pair<int, int> > P; //コスト、現在地、どこからきたか

//int dy[5] = { 0,0,1,-1,0 };
//int dx[5] = { 1,-1,0,0,0 };

int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};

struct edge
{
	int to;
	double cost;
};

int main(void)
{
	while(1){
		long long int n, q;
		string tmp;
		long long int a, b;
		cin >> n >> q;

		if(n==0&&q==0){
			break;
		}
		vector<string> s(n);
		vector<long long int> first(n), second(n);
		FOR(i, 0, n - 1)
		{
			cin >> tmp >> a >> b;
			s[i] = tmp;
			first[i] = b - a + 1;
			second[i] = b;
		}
		bool flag = false;
		FOR(i, 1, q)
		{
			cin >> a;
			flag = false;
			FOR(j, 0, n - 1)
			{
				if(first[j]<=a&&second[j]>=a){
					cout << s[j] << " " << a - first[j] + 1 << endl;
					flag = true;
				}
			}
			if(flag==false){
				cout << "Unknown" << endl;
			}
		}
	}
	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>
#define MAX_N 1000
#define INF 2000000000
using namespace std;

string eraname[MAX_N];
int erabased[MAX_N], western[MAX_N];
int erafirst[MAX_N];

void search(int y, int n) {
  for (int i = 0; i < n; i++) {
    int temp = y - erafirst[i];
    if (0 < temp && temp <= erabased[i]) {
      cout << eraname[i] << ' ' << temp << endl;
      return;
    }
  }
  cout << "Unknown" << endl;
  return;
}

void init() {
  for (int i = 0; i < MAX_N; i++) {
    eraname[i] = erabased[i] = western[i] = 0;
    erafirst[i] = INF;
  }
}

int main() {
  while (true) {
    int n, q;
    cin >> n >> q;
    if (n == 0 && q == 0) return 0;

    init();

    for (int i = 0; i < n; i++) {
      cin >> eraname[i] >> erabased[i] >> western[i];
    }

    for (int i = 0; i < n; i++) {
      erafirst[i] = western[i] - erabased[i];
    }

    for (int i = 0; i < q; i++) {
      int query;
      cin >> query;

      search(query, n);
    }
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
using Pair = pair<int, int>;
const int INF = 1 << 30;

enum { START, END };

int N, Q;

void solve() {
    vector<Pair> A;
    map<int, string> mp;
    for(int i = 0; i < N; ++i) {
        string s;
        int e, w;
        cin >> s >> e >> w;
        int start = w - e + 1;
        A.emplace_back(start, START);
        A.emplace_back(w, END);
        mp[start] = s;
    }
    A.emplace_back(INF, START);
    sort(A.begin(), A.end());
    while(Q--) {
        int y; cin >> y;
        auto end = upper_bound(A.begin(), A.end(), make_pair(y, 0));
        if(end->second == 0) {
            cout << "Unknown" << '\n';
        } else {
            auto start = prev(end);
            cout << mp[start->first] << " " << y - start->first + 1 << '\n';
        }
    }
}

int main() {
    while(cin >> N >> Q) {
        if(!N) break;
        solve();
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,string> P;
typedef pair<int,P > PP;

int main(){
  int n,q;
  while(cin>>n>>q,n){
    PP pr[1000];
    for(int i=0;i<n;i++){
      string s;
      int a,b;
      cin>>s>>a>>b;
      pr[i]=PP(b,P(a,s));
    }
    for(int i=0;i<q;i++){
      int x;
      cin>>x;
      int ok=n-1,ng=-1,mid;
      while(ok-ng>1){
	mid=(ok+ng)/2;
	if(pr[mid].first>=x)ok=mid;
	else ng=mid;
      }
      int t=pr[ok].first-x;
      int k=pr[ok].second.first;
      if(t<k)cout<<pr[ok].second.second<<" "<<k-t<<endl;
      else cout<<"Unknown"<<endl;
    }
  }
    return 0;
}

C++: // AOJ 0029 English Sentence
// ??????0??????????£? 5???
// map????????£?????°???????????????????????§???????????????????????¬??????????????????????¢?????????????
#include <iostream>
#include <map>
#include <string>
using namespace std;
int N,Q;
string era[10010];
int eby[10010],wy[10010];
int solve(){
	cin >> N >> Q;
	if(N+Q==0)return 1;
	for(int i=0;i<N;i++){
		cin >> era[i] >> eby[i] >> wy[i];
	}
	for(int i=0;i<Q;i++){
		int tar;
		cin >> tar;
		bool known = false;
		for(int j=0;j<N;j++){
			if(wy[j]-eby[j]<tar&&tar<=wy[j]){
				cout << era[j] << ' ' << tar-(wy[j]-eby[j]) << endl;
				known = true;
				break;
			}
		}
		if(!known)cout << "Unknown" << endl;
	}
	return 0;
}
int main(){
	while(!solve()){}
	return 0;
}

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

using namespace std;

class era{
public:
    era(string s, int b, int l){
        name = s;
        begin = b;
        len = l;
    }

    string name;
    int begin;
    int len;
};

int main(){
    int n,q;
    while(cin >> n >> q && n+q!=0){
        vector<era> v;
        string str;
        int len,begin,query;
        for(int i=0;i<n;i++){
            cin >> str >> len >> begin;
            v.push_back(era(str, begin-len+1, len));
        }
        for(int i=0;i<q;++i){
            bool isok = false;
            cin >> query;
            for(int j=0;j<n;++j){
                if(v[j].begin <= query &&
                   query < v[j].begin + v[j].len){
                    isok = true;
                    cout << v[j].name << " " << query - v[j].begin+1 << endl;
                }
            }
            if(!isok) cout << "Unknown" << endl;
        }
    }
}