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>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    while(true){
        vector<tuple<ll, ll, string>> v;
        ll n, q; cin >> n >> q;
        if(n==0 && q==0) break;
        map<string, ll> era_begin;
        rep(i, n){
            string eraname;
            ll erayear, westernyear;
            cin >> eraname >> erayear >> westernyear;
            v.push_back(make_tuple(westernyear - erayear, westernyear, eraname));
        }
        sort(v.begin(), v.end());
        rep(i, q){
            ll que; cin >> que;
            bool ifdetermined = false;
            rep(i, v.size()){
                if(get<0>(v[i]) < que && que <= get<1>(v[i])){
                    cout << get<2>(v[i]) << ' ' << que - get<0>(v[i]) << endl;
                    ifdetermined = true;
                }
            }
            if(!ifdetermined) cout << "Unknown" << endl;
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    string name[1000];
    int eb[1000], we[1000], query;
    while (true) {
        cin >> n >> q;
        if(n == 0 && q == 0) break;
        for (int i = 0; i < n; ++i) {
            cin >> name[i] >> eb[i] >> we[i];
        }
        for (int i = 0; i < q; ++i) {
            cin >> query;
            int ind = 0;
            for (; ind < n; ++ind) {
                if(we[ind] >= query &&
                        we[ind] - eb[ind] + 1 <= query) {
                    break;
                }
            }
            if (ind < n) {
                cout << name[ind] << ' '
                     << eb[ind] - we[ind] + query
                     << endl;
            } else {
                cout << "Unknown" << endl;
            }
        }
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
  while(true){
    int N,Q;
    cin >> N >> Q;
    if(N==0&&Q==0)break;
    map<long long int,string> M;
    for(int i = 0; i < N; ++i){
      string era;
      long long int now;
      long long int y;
      cin >> era >> now >> y;
      M[y-now+1]=era;
      M[y]=era;
    }
    for(int i = 0; i < Q; ++i){
      long long int y;
      long long int res=-1;
      string res_era;
      cin >> y;
      map<long long int,string>::iterator itm = M.lower_bound(y);
      if(itm==M.end())itm=M.begin();
      if(itm!=M.begin()){
	--itm;
      }
      while(true){
	if(itm==M.end())break;
	if(itm->first>y){
	  break;
	}else{
	  map<long long int,string>::iterator itm2 = itm;
	  itm2++;
	  if(itm2==M.end())break;
	  if( y >= itm->first && y <= itm2->first && itm->second == itm2->second ){
	    res = y - itm->first + 1;
	    res_era = itm->second;
	  }
	}
	++itm;
      }
      if(res>0){
	cout << res_era << ' ' << res << endl;
      }else{
	cout << "Unknown" << endl;
      }
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q, _e, _w, _q;
    string _s;
    while(cin >> N >> Q && N){
        map<int, string> cvt;
        map<int, int> cvt2;
        int start, last;
        rep(i, N){
            cin >> _s >> _e >> _w;
            cvt[_w] = _s;
            cvt2[_w] = _w - _e;
            if(i == 0) start = _w - _e + 1;
            if(i == N - 1) last = _w;
        }
        rep(i, Q){
            cin >> _q;
            if(_q < start || last < _q)
              cout << "Unknown" << endl;
            else{
                auto lb = cvt.lower_bound(_q);
                string sa = lb->second;
                int ia = _q - cvt2[lb->first];
                if(ia >= 1)
                  cout << sa << ' ' << ia << endl;
                else
                  cout << "Unknown" << endl;
            }
        }
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

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

    while (true)
    {
        ll n, q;
        cin >> n >> q;
        if (n == 0 && q == 0)
            break;
        std::vector<string> ename;
        std::vector<ll> eyear, wyear;
        for (int i = 0; i < n; i++)
        {
            string s;
            ll a, b;
            cin >> s >> a >> b;
            ename.push_back(s);
            eyear.push_back(a);
            wyear.push_back(b);
        }
        for (int i = 0; i < q; i++)
        {
            ll y;
            cin >> y;
            bool flag = false;
            for (int j = 0; j < n; j++)
            {
                int st = wyear[j] - eyear[j] + 1;
                if (st <= y && y <= wyear[j])
                {
                    cout << ename[j] << " " << y - st + 1 << endl;
                    flag = true;
                    break;
                }
            }
            if (!flag)
                cout << "Unknown" << endl;
        }
    }
    return 0;
}

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

using std::cin;
using std::cout;
using std::endl;

int check_ind(std::vector< std::pair< int, std::string > > v, int w) {
	int l = v.size();
	for (int i = 0; i < l; i++) {
		if ( v[l-i-1].first <= w ) {
			return (l-i-1);
		}
	}
	return -1;
}

int main(void) {
	int N,Q;
	cin >> N >> Q;

	while ( N != 0 || Q != 0 ) {
		std::vector< std::pair< int, std::string > > G(N);
		std::vector< std::pair< int, std::string > > g(N);
		int era,w,min;
		for (int i = 0; i < N; i++) {
			cin >> G[i].second;
			g[i].second = G[i].second;
			cin >> era >> w;
			g[i].first = w;
			G[i].first = w - era + 1;
			if ( i == 0 ) {
				min = G[i].first;
			}
			else {
				if ( G[i].first < min ) {
					min = G[i].first;
				}
			}
		}
		
		std::sort(G.begin(), G.end());
		std::sort(g.begin(), g.end());

		int ind;
		int ret;
		for (int i = 0; i < Q; i++) {
			cin >> w;
			ind = check_ind(G,w);
			if ( ind < 0 ) {
				cout << "Unknown" << endl;
			}
			else {
				ret = w - G[ind].first + 1;
				if ( !(w > g[ind].first) ) {
					cout << G[ind].second << " " << (w - G[ind].first + 1) << endl;
				}
				else {
					cout << "Unknown" << endl;
				}
			}
		}

		cin >> N >> Q;
	}

	return 0;
}