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 <map>
#include <string>
#include <iostream>
using namespace std;
struct er{
    string gengo;
    int start;
    int end;
};

int main(){
    int N,Q,i,f,t,y;
    string buf;
    map<int,er> mp;
    while(1){
        mp.clear();
        cin >> N >> Q;
        if(!N && !Q){break;}
        for(i=0;i<N;i++){
            cin >> buf >> f >> t;
            struct er e={buf,t-f+1,t};
            mp[t-f+1]=e;
        }
        for(i=0;i<Q;i++){
            cin >> y;
            auto itr=mp.upper_bound(y);
            if(itr!=mp.begin()){
                itr--;
            }
            if(itr->second.start <= y && itr->second.end >= y){
                cout << itr->second.gengo << " " << y-itr->first+1 << endl;
            }
            else{
                cout << "Unknown" <<endl;
            }
        }
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long int ll;

int main(){
	while(1){
		ll n,q;cin>>n>>q;
		vector<pair<pair<ll,ll>,string> > v(n);
		vector<ll> u(n);
		//その西暦のスタート、そこが何年か（その西暦のゴール）、時代名

		if(n==0 && q==0)return 0;

		for (int i = 0; i < n; ++i)
		{
			ll x,y;string s;
			cin>>s>>x>>y;

			v[i].second=s;
			v[i].first.first=y-x+1;
			v[i].first.second=y;
			u[i]=y-x+1;
		}

		sort(v.begin(),v.end());
		sort(u.begin(),u.end());

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

			ll it=upper_bound(u.begin(),u.end(),z)-u.begin();

			if(it>0 && v[it-1].first.first<= z && z<=v[it-1].first.second){
				cout<<v[it-1].second <<" "<<z-v[it-1].first.first+1<<endl;
			}else{
				cout<<"Unknown"<<endl;
			}
		}
	}
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,q;
  while(cin >> n >> q && n+q){
    string s;
    ll a,b;
    vector<ll> x(n);
    vector<pair<ll,string>> v(n);
    rep(i,n){
      cin >> s >> a >> b;
      v[i] = mp(a,s);
      x[i] = b;
    }
    ll k;
    rep(i,q){
      cin >> k;
      auto it =lower_bound(all(x),k);
      auto dis = distance(x.begin(),it);
      if(dis < n && v[dis].fi + k - *it > 0){
        cout << v[dis].se + " " <<v[dis].fi + ( k - *it) << endl;
      }
      else{
        cout << "Unknown" << endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    while (1) {
        int n, q;
        cin >> n >> q;
        if (n == 0 && q == 0) return 0;
        
        vector<pair<int, string> > nengo;
        for (int i = 0; i < n; i++) {
            string s;
            int ny, wy;
            cin >> s >> ny >> wy;
            nengo.emplace_back(wy - (ny - 1), s);
            nengo.emplace_back(wy, "0");
        }
        sort(nengo.begin(), nengo.end());
        
        for (int i = 0; i < q; i++) {
            int qy, in = 0;
            cin >> qy;
            for (int j = 0; j < nengo.size(); j++) {
                if (nengo[j].first < qy) {
                    if (nengo[j].second == "0") in--;
                    else in++;
                }
                else if (nengo[j].first == qy && nengo[j].second != "0") in++;
                else {
                    if (in == 0) cout << "Unknown" << endl;
                    else cout << nengo[j - 1].second << " " << qy + 1 - nengo[j - 1].first << endl;
                    break;
                }
            }
        }
    }
}

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

int main() {
  int n, q;
  while (cin >> n >> q, n > 0) {
    vector<tuple<int, int, string>> eras(n);  // (開始年, 終了年, 元号)
    for (int i = 0; i < n; i++) {
      int diff;
      cin >> get<2>(eras[i]) >> diff >> get<1>(eras[i]);
      get<0>(eras[i]) = get<1>(eras[i]) - diff + 1;
    }
    for (int i = 0; i < q; i++) {
      int year;
      cin >> year;
      bool flag = false;
      for (int j = 0; j < n; j++) {
        if (get<0>(eras[j]) <= year && year <= get<1>(eras[j])) {
          cout << get<2>(eras[j]) << ' ' << year - get<0>(eras[j]) + 1 << endl;
          flag = true;
          break;
        }
      }
      if (!flag) cout << "Unknown" << endl;
    }
  }
  return 0;
}

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

int N,Q;
int main(){
	while (std::cin >>N >>Q && N){
		std::map<int,std::string> start; // 西暦=> その年に始まった元号の名前
		std::map<std::string,int> finish; // 元号=> 何年まで続いたことがわかっているか
		
		std::string name;
		for(int i=0;i<N;++i){
			int local, western;
			std::cin >> name >> local >> western;
			start[western-local+1]=name;
			if(western>finish[name]) finish[name]=western;
		}
		for(int i=0;i<Q;++i){
			int western;
			std::cin >> western;
			bool isUnknown=true;
			for (auto& pair : start){
				if(pair.first<=western && finish[pair.second]>=western){
					std::cout << pair.second << " " << western-pair.first+1 << std::endl;
					isUnknown=false;
					break;
				}
			}
			if(isUnknown) std::cout << "Unknown" << std::endl;
		}
	}
	return 0;
}

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

using namespace std;

#define MAX 1000000000

int main(){

	string data[MAX+1];
	int yeda[MAX+1];
	string en;
	int N,Q,eby,wy;
	int qu;
	string tm;

	while(1){
		cin>>N>>Q;
		if(N==0&&Q==0) break;
		for(int i=1;i<=MAX;i++){
			data[i]="Unkown";
			yeda[i]=-1;
		}
		for(int i=0;i<N;i++){
			cin>>en>>eby>>wy;
			for(int i=0;i<10;i++){
				data[wy-eby+1+i]=en;
				yeda[wy-eby+1+i]=i+1;
			}
		}
		for(int i=0;i<Q;i++){
			cin>>qu;
			if(data[qu]!="Unkown") cout<<data[qu]<<" "<<yeda[qu]<<endl;
			else cout<<"Unkown"<<endl;
		}
	}

	return 0;
}