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


using namespace std;

typedef  pair<int,int> info;


int main(){


  while(1){
    int n,q;
    cin >> n >> q;
    if(n== 0 && q==0) break;

    map<int, string> iniera_map;
    map<string, int> era_years;
    vector<int> iniera_list;

    for(int i=0;i<n;i++){
      // n
      string name;
      int erayear,wyear;
      cin >> name >> erayear >> wyear;
      iniera_map[wyear-erayear+1] = name;
      if(era_years.find(name) == era_years.end())
	era_years[name] = erayear-1;
      else if(era_years[name] > erayear-1){
	era_years.erase(name);
	era_years[name] = erayear-1;
      }
      iniera_list.push_back(wyear-erayear+1);
    }
    sort(iniera_list.begin(),iniera_list.end());
    for(int i=0;i<iniera_list.size();i++){
      //      cout << iniera_list[i] << " ";
    }

    for(int i=0;i<q;i++){
      // query
      int wyear;
      cin >> wyear;
      int eraid,j;
      for(j=iniera_list.size()-1;j>=0; j-- ){
	if(iniera_list[j] <= wyear ) break;
      }
      eraid = j;
      if(j==-1){
	cout << "Unknown\n";
	continue;
      } 
      //      cout << wyear<< " " << iniera_list[eraid] << "~" << iniera_list[eraid] + era_years[iniera_map[iniera_list[eraid]]]  << "\n"; 
      if(iniera_list[eraid] <= wyear ){
	if(wyear <= iniera_list[eraid] + era_years[iniera_map[iniera_list[eraid]]] )
	  cout << iniera_map[iniera_list[eraid]] << " " << wyear - iniera_list[eraid] + 1  << "\n";
       	else
	  cout << "Unknown\n";
      }

      //      string ans_era = iniera_map[];
      //cout << ans_era << " " ;

    }

  }


}

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

using namespace std;

int N, Q;

struct Era {
	string name;
	int ey, gy;
};
bool operator < (const Era& e1, const Era& e2) {
	return e1.gy < e2.gy;
}

vector<Era> v;

void solve(int y) {
	int p = N;
	for (int i = 0; i < N - 1; i++) {
		if (v[i].gy <= y && y <= v[i + 1].gy) {
			p = i;
			break;
		}
	}
	
	if (p == N) {
		if (y < v[0].gy) {
			if (y < v[0].gy - v[0].ey) cout << "Unknown" << endl;
			else cout << v[0].name << " " << v[0].ey - (v[0].gy - y) << endl;
		}
		else if (y > v[N - 1].gy) {
			cout << "Unknown" << endl;
		}
		else {
			cout << v[N - 1].name << " " << v[N - 1].ey + (y - v[N - 1].gy) << endl;
		}
	} else {
		if (v[p + 1].gy - v[p + 1].ey + 1 > y) {
			if (v[p].gy < y) cout << "Unknown" << endl;
			else cout << v[p].name << " " << v[p].ey + (y - v[p].gy) << endl;
		} else {
			cout << v[p + 1].name << " " << v[p + 1].ey + (y - v[p + 1].gy) << endl;
		}
	}
}

int main() {
	while (cin >> N >> Q, N) {
		v.clear();
		for (int i = 0; i < N; i++) {
			string name; int ey, gy;
			cin >> name >> ey >> gy;
			v.push_back((Era){name, ey, gy});
		}
		sort(v.begin(), v.end());
		
		for (int i = 0; i < Q; i++) {
			int y; cin >> y;
			solve(y);
		}
	}
	
	return 0;
}

C++: #include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, q;
  while (cin >> n >> q) {
    if (n == 0 && q == 0) break;
    map<string, pair<int, int>> mp;
    rep(i, n) {
      string s;
      int a, b;
      cin >> s >> a >> b;
      if (mp.count(s)) {
        int right = mp[s].second;
        if (right < b) {
          mp[s] = make_pair(mp[s].first, right);
        }
      } else {
        mp[s] = make_pair(b - a + 1, b);
      }
    }
    while (q--) {
      int c;
      cin >> c;
      bool flag = true;
      for (auto x : mp) {
        if (x.second.first <= c && c <= x.second.second) {
          cout << x.first << ' ' << c - x.second.first + 1 << endl;
          flag = false;
          break;
        }
      }
      if (flag) cout << "Unknown" << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
struct data{
    string str;
    int y,l;
    data(string a,int b,int c):
        str(a),l(b),y(c){}

    data(){}
};
int main(){
    int n,m;
    while(cin>>n>>m,n||m){
        vector<data>V(n);
        for(int i=0;i<n;i++){
            string str;
            int l,y;
            cin>>str>>l>>y;
            V[i]=data(str,l,y);
        }
        while(m--){
            int y;
            cin>>y;
            bool flag=true;
            for(int i=0;i<n;i++){
                if(V[i].y>=y&&V[i].y-V[i].l<y){
                    flag=false;
                    cout<<V[i].str<<" "<<y-V[i].y+V[i].l<<endl;
                    break;
                }
            }
            if(flag)cout<<"Unknown"<<endl;
        }

    }

    return 0;
}

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

using namespace std;

typedef pair<string, int> P;

int main()
{
  int N, Q;
  while(cin >> N >> Q, N || Q){
    map<int, P> mp;
    while(N--){
      string eraname;
      int base, west;
      cin >> eraname >> base >> west;
      mp[west] = P(eraname, base);
    }
    while(Q--){
      int y;
      cin >> y;
      map<int, P>::iterator it = mp.lower_bound(y);
      if(it == mp.end()){
	cout << "Unknown" << endl;
      } else if(it->first - (it->second).second < y && y <= it->first){
	cout << (it->second).first << " " << y - it->first + (it->second).second << endl;
      } else {
	cout << "Unknown" << endl;
      }
    }
  }
  return 0;
}