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 <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

struct Era{
	string name;
	int start, end;
};

int main()
{
	ios_base::sync_with_stdio(0);
	int N, Q;
	while (cin >> N >> Q, N ){
		Era era[N];
		rep (i, N ){
			int y1, y2;
			cin >> era[i].name >> y1 >> y2;
			era[i].end = y2;
			era[i].start = y2 - y1 + 1;
		} // end rep
		rep (j, Q ){
			int year; cin >> year;

			string ans1 = "";
			int ans2 = 0;
			rep (i, N ){
				if (era[i].start <= year && year <= era[i].end ){
					ans1 = era[i].name;
					ans2 = year - era[i].start + 1;
					break;
				} // end if
			} // end rep

			if (ans2 != 0 ){
				cout << ans1 << ' ' << ans2 << endl;
			}else{
				cout << "Unknown" << endl;
			} // end if
		} // end rep
	} // end while
		
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n, q;
	while (scanf("%d%d", &n, &q), n) {
		map<int, string>mp;
		rep(i, n) {
			string s;
			int j, k;
			cin >> s >> j >> k;
			mp[k - j] = s;
		}
		rep(i, q) {
			int d; scanf("%d", &d);
			auto it = mp.lower_bound(d);
			it--;
			if (it == --mp.begin()) {
				puts("Unknown");
				continue;
			}
			if ((*it).first == d || (++it != mp.end()) && ((*++it).first - d == 1)) {
				puts("Unknown");
				continue;
			}
			cout << (*it).second << ' ' << d - (*it).first << endl;
		}
	}
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000
using namespace std;
typedef pair<int, int> P;
typedef pair<P, string> Pi;
#define fi first
#define sec second
int main()
{
    int n, q;
    while (cin >> n >> q)
    {
        if (n == 0 && q == 0)
            break;
        string str;
        vector<Pi> vec(n + 1);
        int era[n + 1];
        int westerm[n + 1];
        rep(i, n)
        {
            cin >> str >> era[i] >> westerm[i];
            vec[i].fi.fi = westerm[i] - era[i] + 1;
            vec[i].fi.sec = westerm[i];
            vec[i].sec = str;
        }
        vector<int> year(q + 1);
        rep(i, q) cin >> year[i];
        rep(i, q)
        {
            bool flag = false;
            rep(j, n)
            {
                if (year[i] >= vec[j].fi.fi && year[i] <= vec[j].fi.sec)
                {
                    flag = true;
                    cout << vec[j].sec << " " << year[i] - westerm[j] + era[j] << endl;
                    break;
                }
            }
            if (!flag)
                cout << "Unknown" << endl;
        }
    }
    return 0;
}

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

int main(){

  for(int n,q;cin>>n>>q,n;){
    vector<pair<string, pair<int, int >>> era;

    for(int i=0;i<n;++i){
      string a;int b,c;
      cin>>a>>b>>c;
      era.push_back(make_pair(a,make_pair(c-b,c)));
    }

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

      for(int j=0;j<n;++j){
        if(era[j].second.first<query&&query<=era[j].second.second){
          cout << era[j].first << " " << query-era[j].second.first << endl;
          break;
        }

        if(j==n-1) cout << "Unknown" << endl;
      }
    }
  }

  return 0;
}

C++: #include<bits/stdc++.h>
#define int long long
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

signed main() {
	int n, q;
	while (cin >> n >> q, n) {
		map<int, string>mp;
		map<string, int>m;
		rep(i, n) {
			string s;
			int j, k;
			cin >> s >> j >> k;
			mp[k - j] = s;
			m[s] = j;
		}
		rep(i, q) {
			int d; cin >> d;
			auto it = mp.lower_bound(d);
			it--;
			if (it == --mp.begin()) {
				puts("Unknown");
				continue;
			}
			if (d - (*it).first > m[(*it).second]) {
				puts("Unknown");
				continue;
			}
			cout << (*it).second << ' ' << d - (*it).first << endl;
		}
	}
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
struct era{
  int s,e;
  string name;
  bool operator<(const era&e)const{
    return s < e.s;
  }
};
int main(){
  int n,q;
  int i,j,k;
  era e;
  string str;
  int b,w;
  cin >> n >> q;
  while(n+q!=0){
    vector<era> v;
    for(i=0;i<n;i++){
      cin >> str >> b >> w;
      e.name=str;
      e.s=w-b+1;e.e=w;
      v.push_back(e);
    }
    sort(v.begin(),v.end());
    for(i=0;i<q;i++){
      cin >> b;
      int st=0,en=v.size()-1,no;
      no=(st+en)/2;
      for(j=0;j<100;j++){
	if(v[no].s<b) st = no;
	else en=no;
	no=(st+en)/2;
      }
      if(v[no].s<=b&&b<=v[no].e) cout << v[no].name <<" "<<  (b-v[no].s+1) << endl;
      else cout << "Unknown" << endl;
    }
    
    cin >> n >> q;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pii;
int main(){
  int N, Q;
  while(scanf("%d%d", &N, &Q) && N+Q){

    vector<string>era(N);
    vector<pii>year(N);
    int a, b;
    string s;
    rep(i, N){
      cin >> s;
      era[i] = s;
      scanf("%d%d", &a, &b);


      year[i] = make_pair(b-a+1, b);
    }

    rep(i, Q){
      scanf("%d", &a);
      rep(i, year.size()){
	if(i+1 == year.size() && (year[i].F > a || year[i].S < a)) puts("Unknown");
	if(year[i].F > a || year[i].S < a) continue;
	cout << era[i];
	printf(" %d\n", a-year[i].F+1);
	break;
      }
    }
  }
  return 0;
}