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 <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int n, int m) {
    using type = pair<int, pair<int, string>>;
    vector<type> gen(n);
    for_each(ALL(gen), [](type &e) {
        string s;int a, b;
        cin >> s >> a >> b;
        e = MP(b, MP(a, s));
    });
    SORT(gen);
    VI ids(n);
    REP(i, n) ids[i] = gen[i].first;
    REP(i, m) {
        int num; cin >> num;
        int idx = lower_bound(ALL(ids), num) - begin(ids);
        auto e = gen[idx];
        if (e.second.first - (e.first - num) > 0) {
            cout << e.second.second << " " << e.second.first - (e.first - num) << endl;
        } else {
            cout << "Unknown" << endl;
        }
    }
    return;
}

signed main(void) {
    LL n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n >> m, n) {
        solve(n, m);
        //return 0;
    }
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    vector<string> ans;

    while(1){
        ll n, q; cin >> n >> q;
        if(n == 0 && q == 0) break;
        // start, end, name
        vector<pair<pair<ll, ll>, string> > era; 

        for(int i=0;i<n;i++){
            string name;
            ll eyear, wyear;
            cin >> name >> eyear >> wyear;
            ll st = wyear - eyear;
            ll ed = wyear;
            era.push_back(make_pair(make_pair(st, ed), name));
        }

        for(int i=0;i<q;i++){
            ll y; cin >> y;
            bool known = false;
            for(auto e: era){
                if(y > e.first.first && y <= e.first.second){
                    string name = e.second;
                    ll num = y - e.first.first;
                    known = true;
                    ans.push_back(name + " " + to_string(num));
                    break;
                }
            }
            if(!known) ans.push_back("Unknown");
        }
    }
    for(string a: ans) cout << a << endl;
}

C++: #include <vector>
#include <string>
#include <iostream>
using namespace std;
int main(){
	int N,Q,i,x,y;
	string s;
	for(;cin>>N>>Q,N;){
		vector<pair<int,pair<int,string> > >v;
		for(i=0;i<N;i++)cin>>s>>x>>y,v.push_back(make_pair(y-x,make_pair(y,s)));
		for(i=0;i<Q;y<N?cout<<v[y].second.second<<' '<<x-v[y].first<<endl:cout<<"Unknown"<<endl,i++)for(cin>>x,y=0;y<N;y++)if(v[y].first<x&&x<=v[y].second.first)break;
	}
}

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

using namespace std;

typedef pair<int, int> Range;
typedef pair<Range, string> Pair;

int main() {
  int n, q, query, based, western;
  string name;
  Pair pairs[1000];
  while (true) {
    cin >> n >> q;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      cin >> name >> based >> western;
      pairs[i].first = Range(western - based, western);
      pairs[i].second = name;
    }
    sort(pairs, pairs + n);
    for (int i = 0; i < q; ++i) {
      cin >> query;
      for (int j = 0; j < n; ++j) {
        if (pairs[j].first.first < query and query <= pairs[j].first.second) {
          cout << pairs[j].second << " " << query - pairs[j].first.first << endl;
          goto last;
        }
      }
    cout << "Unknown" << endl;
last:
    continue;
    }
  }
}

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

using namespace std;

int main(int argc, char const *argv[])
{
	int n,q;
	int ey,wy;
	string en;
	map<pair<int,int>, string>::iterator it;

	while(1){
		cin>>n>>q;
		if(n+q==0) break;

		map<pair<int,int>, string> mp;
		for(int i1=0;i1<n;i1++){
			cin>>en>>ey>>wy;
			mp[make_pair(wy-ey+1,wy)]=en;
		}

		for(int i1=0;i1<q;i1++){
			cin>>ey;
			for(it=mp.begin();it!=mp.end();it++){
				if((*it).first.first <= ey && (*it).first.second >= ey) {
					cout<<(*it).second<<" "<<ey-(*it).first.first+1<<endl;
					break;
				}
			}
			if(it==mp.end()) cout<<"Unknown"<<endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string S[100],U;int n,a,b,c,d,p[100][2];char T[11]="0123456789";
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-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++: #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++){
			int eby;
			cin >> data[i].name >> eby >> data[i].end;
			data[i].start = data[i].end-eby;
		}
		
		for(int i=0; i<q; i++){
			bool found = false;
			int year;
			cin >> year;
			for(int j=0; j<n; j++){
				if(data[j].start<year && year<=data[j].end){
					cout << data[j].name << " " << year-data[j].start << endl;
					found = true;
					break;
				}
			}
			if(!found){
				cout << "Unknown" << endl;
			}
		}
	}
	return 0;
}