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 <map>
#include <algorithm>
#include <utility>

using namespace std;
typedef pair<int, string> pis;

int main(){
	while(true){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0){ break; }
		vector<pis> v(n);
		map<int, int> last;
		for(int i = 0; i < n; ++i){
			int a, b;
			cin >> v[i].second >> a >> b;
			v[i].first = b - a + 1;
			last[v[i].first] = b;
		}
		sort(v.begin(), v.end());
		while(m--){
			int y;
			cin >> y;
			vector<pis>::iterator it =
				lower_bound(v.begin(), v.end(), pis(y, ""));
			if(it == v.begin() && y < it->first){
				cout << "Unknown" << endl;
			}else if(it->first == y){
				cout << it->second << " " << 1 << endl;
			}else{
				--it;
				int jy = (y - it->first + 1);
				if(y <= last[it->first]){
					cout << it->second << " " << jy << endl;
				}else{
					cout << "Unknown" << endl;
				}
			}
		}
	}
	return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

int N, Q;
string s;
int x, y;
int q;

int main()
{
  while(cin >> N >> Q, N){
    vi data(N);
    map<int, pair<int, string> > hm;
    rep(i, N){
      cin >> s >> x >> y;
      data[i] = y - x + 1;
      hm[y - x + 1] = mp(y, s);
    }
    sort(ALL(data));

    while(Q--){
      cin >> q;
      int pos = upper_bound(ALL(data), q) - data.begin();
      if(hm[data[pos - 1]].first >= q){
        cout << hm[data[pos - 1]].second << ' ' << q - data[pos - 1] + 1 << endl;
      }
      else cout << "Unknown" << endl;
    }
  }

  return 0;
}

C++: #include <string>
#include <iostream>
using namespace std;
int N, Q, v[1000], w[1000], x; char s[1000][20];
int main() {
	while (cin >> N >> Q, N | Q) {
		for (int i = 0; i < N; i++) scanf("%s%d%d", s[i], &v[i], &w[i]);
		for (int i = 0; i < Q; i++) {
			scanf("%d", &x); int f = 0;
			for (int j = 0; j < N; j++) {
				if (w[j] - v[j] < x && x <= w[j]) {
					printf("%d %d\n", s[j], x - w[j] + v[j]); f = 1; break;
				}
			}
			if (!f) cout << "Unknown" << endl;
		}
	}
}

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 <vector>
#include <algorithm>
#include <tuple>

using namespace std;

#define all(c) (c).begin(), (c).end()

int main(){
    int N, Q;
    while(cin >> N >> Q, N|Q){
        typedef tuple<int, int, string> Data;
        vector<Data> era;
        while(N--){
            string name;
            int eyear, wyear;
            cin >> name >> eyear >> wyear;
            era.emplace_back(wyear - eyear + 1, wyear, name);
        }
        sort(all(era));
        while(Q--){
            int query, one, known;
            string name;
            cin >> query;
            tie(one, known, name) = *lower_bound(all(era), query,
                                                 [](Data& d, int x){return get<1>(d) < x;});
            if(one <= query && query <= known)cout << name << " " << query - one + 1 << '\n';
            else cout << "Unknown\n";
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
 
typedef pair<int,int> P;
 
int main(){
    int N, Q;

    while( cin >> N >> Q, N || Q ){
        // m[name] := 和暦nameに対応する(和暦,西暦の最大)の組を返す.
        map<string, P> m;
        // v := 和暦の名前を保持
        vector<string> v;
         
        for(int i = 0 ; i < N ; i++ ){
            // name := 和暦の名前, y1 := 和暦, y2 := 西暦
            string name;
            int y1, y2;
             
            cin >> name >> y1 >> y2;
            if( m.count(name) ){
                if( m[name].second < y2 ){
                    m[name] = P(y1, y2);
                }
            }else{
                m[name] = P(y1, y2);
                v.push_back( name );
            }
        }
         
        for(int i = 0 ; i < Q ; i++ ){
            int q;
            cin >> q;
            
            // flag := 解が存在するかどうか.
            bool flag = false; 
            for(int j = 0 ; j < v.size() ; j++ ){
                int y1 = m[v[j]].first;
                int y2 = m[v[j]].second;
                
                // 和暦[1,y1] <=> 西暦[y2-y1+1, y2] と対応している.
                // 対応があるとき
                if( y2 - y1 + 1 <= q && q <= y2 ){ 
                    flag = true;
                    int ans = q - (y2 - y1);
                    // 解の出力
                    cout << v[j] << " " << ans << endl;
                    break;
                }
            }
            
            // 解が存在しないとき
            if( !flag ){
                cout << "Unknown" << endl;
            }
        }
    }
}