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>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<functional>
#include<fstream>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
#define f first
#define s second

int main(){
  int n,m;

  while(cin>>n>>m){
    vector<pair<int,pair<int,string> > > jp(n);
    REP(i,n){
      int a,b;
      string s;
      cin>>s>>a>>b;
      jp[i].f = b - a + 1;
      jp[i].s.f = a;
      jp[i].s.s = s;
    }

    sort(jp.begin(), jp.end());

    REP(i,m){
      int ans = -1;
      int q;
      cin>>q;
      REP(j,n){
        if(jp[j].f <= q && jp[j].f+jp[j].s.f > q){
          ans = j;
          break;
        }
      }
      if(ans == -1) cout << "Unknown" << endl;
      else cout << jp[ans].s.s << " " << q - jp[ans].f + 1 << endl;
    }
  }
  return 0;
}

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

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

int n, q;

class node
{
public:
	string name;
	int start, end;

	node(string n, int a, int b):name(n), start(b-a+1), end(b){}

	bool is_in_range(int year)
	{
		return start <= year && year <= end;
	}
};

int main(void)
{
	while(cin >> n >> q, n|q) {
		vector<node> vs;
		rep(i, n) {
			string name;
			int erabased, westernyear;
			cin >> name >> erabased >> westernyear;
			vs.push_back(node(name, erabased, westernyear));
		}

		rep(i, q) {
			int year;
			cin >> year;
			int cnt = 0, idx = -1;
			rep(j, vs.size()) {
				if(vs[j].is_in_range(year)) {
					//printf("%s %d\n", vs[j].name.c_str(), year-vs[j].start+1);
					idx = j;
					cnt++;	
				}
			}
			if (cnt != 1)
				printf("Unkown\n");
			else
				printf("%s %d\n", vs[idx].name.c_str(), year-vs[idx].start+1);
		}
	}
	return 0;
}

C++: #include<iostream>
#include<memory.h>
#include<stdio.h>
using namespace std;
char name[1000][1000];
int n,m;

int main(){
    while(cin>>n>>m && (n+m)!=0){
        long long japan[10000];
        long long japan2[10000];
        long long a,b;

        for(int i=1;i<=n;i++){
        scanf("%s",name[i]);
        cin>>a>>b;
        japan[i] = b;
        japan2[i] = b-a;
        }


        long long query;
        for(int i=1;i<=m;i++){
            cin>>query;
            int temp = 0;
            for(int i=1;i<=n;i++){
                if(query <= japan[i] && query >japan2[i]){
                    cout<<name[i]<<" "<<( query - japan2[i]) <<endl;
                    temp = 1;
                    break;
                }
            }
            if(temp == 0){cout<<"Unknown"<<endl;}
        }



    }


    return 0;

}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int n, q;
pair<int, string> eras[1000];

void solve(int x) {
	if (x <= eras[0].first) {
		cout << "Unknown" << endl;
		return;
	}
	for (int i = 1; i < n; i++) {
		if (x == eras[i].first) {
			cout << "Unknown" << endl;
			return;
		}
		if (x < eras[i].first) {
			cout << eras[i - 1].second << ' ' << x - eras[i - 1].first << endl;
			return;
		}
	}
	cout << eras[n - 1].second << ' ' << x - eras[n - 1].first << endl;
}

int main () {
	while (cin >> n >> q, n || q) {
		for (int i = 0; i < n; i++) {
			string name;
			int eby, wy;
			cin >> name >> eby >> wy;
			eras[i] = make_pair(wy - eby, name);
		}
		sort(eras, eras + n);
		for (int i = 0; i < q; i++) {
			int x;
			cin >> x;
			solve(x);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
string s[1000];
int e[1000],w[1000];
int main(){
	while(true){
		int n,q;
		cin>>n>>q;
		if(n==0) break;
		rep(i,n) cin>>s[i]>>e[i]>>w[i];
		rep(i,q){
			int y;
			cin>>y;
			bool ok=0;
			rep(j,n) if(w[j]-e[j]<y && y<=w[j]){
				ok=1;
				cout << s[j] << " " << e[j]-w[j]+y << endl;
			}
			if(!ok) cout << "Unknown\n";
		}
	}
}

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

using namespace std;


int main(void) {
    while(1) {
        vector<pair<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.push_back(pair<int,string>(west-base+1, name));
            max[name] = base;
        }
        for(int i=0; i<q; i++) {
            int y;
            cin >> y;
            auto it = upper_bound(begin(dict), end(dict), pair<int,string>(y, string("\xFF")));

            if(it == dict.end())
                it = dict.begin() + (dict.size()-1);
            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;
}

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

int n,q;
string name[1010];
int e_y[1010], w_y[1010];

int main(){
  while(cin >> n >> q, n){
    for(int i=0;i<n;i++){
      cin >> name[i] >> e_y[i] >> w_y[i];
    }
    for(int i=0;i<q;i++){
      int query;
      cin >> query;

      string ans = "Unknown";
      int y = -1;
      for(int j=0;j<n;j++){
	if(w_y[j]-e_y[j]< query && query<=w_y[j]){
	  ans = name[j]; y = e_y[j] - (w_y[j]-query);
	}
      }
      if(y<0)cout << ans << endl;
      else cout << ans << " " << y << endl;
    }
  }
}