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++: #define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	/*if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;*/
	return ((a.x + 1)*(a.y + 1)) < ((b.x + 1)*(b.y + 1));
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll x, ll k, ll p) {//最大値、個数
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
 //#define int long long
const long long Inf = 4523372036854775807;
const int inf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
struct A {
	string s;
	int x;
	bool y;
	//文字列、年、最初か最後か
};
bool operator<(A a, A b) {
	if (a.x != b.x) return a.x < b.x;
	return !a.y;
}
vector<A>a;
vector<int>b;
signed main() {
	int n, q;
	while (cin >> n >> q, n, q) {
		a.clear();
		b.clear();
		for (int i = 0; i < n; i++) {
			string s;
			int u, r;
			cin >> s >> u >> r;
			a.push_back(A{ s,r - u + 1,0 });
			b.push_back(r - u + 1);
			a.push_back(A{ s,r,1 });
			b.push_back(r);
		}
		sort(a.begin(), a.end());
		sort(b.begin(), b.end());
		for (int i = 0; i < q; i++) {
			int t;
			cin >> t;
			int k = upper_bound(b.begin(), b.end(), t) - b.begin() - 1;
			if (k < 0 || (a[k].y&&a[k].x < t)) {
				cout << "Unknown\n";
			}
			else {
				if (a[k].x == t&&a[k].y) k--;
				cout << a[k].s << " " << t - a[k].x + 1 << endl;
			}
		}
	}
	getchar(); getchar();
}

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

int N,Q;

void solve() {

    multimap<int,string> data;
    rep(i,N) {
        string ss;
        int a,b;
        cin>>ss>>a>>b;
        data.insert(make_pair(b-a, ss));
    }
    rep(i,Q) {
        int a;
        cin>>a;
        map<int,string>::iterator it = 
            data.upper_bound(a);
        if(it==data.begin()) {
            cout<<"Unknown"<<endl;
        }
        else {
            it--;
            int t = a-(it->first);
            if(t<=0) {
                cout<<"Unknown"<<endl;

            }
            else {
                cout<<it->second<<" "<<t<<endl;
            }
        }
    }

}

int main() {
    while(cin>>N>>Q) {
        if(N+Q==0) return 0;
        solve();
    }

    return 0;
}

C++: #include<iostream>
#define N 1000
using namespace std;

int main(){
  while(1){
    int n,q,e[N],w[N],que,f;
    string str[N];
    cin>>n>>q;
    if(n+q==0) break;
    for(int i=0;i<n;i++)cin>>str[i]>>e[i]>>w[i];
    for(int i=0;i<q;i++){
      cin>>que,f=0;
      for(int j=0;j<n;j++)if(e[j]-(w[j]-que)>0 && e[j]-(w[j]-que)<=e[j]) cout<<str[j]<<" "<<e[j]-(w[j]-que)<<endl,f=1;
      if(!f) cout<<"Unknown"<<endl;
    }
  }
  return 0;
}

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

using namespace std;

struct P{
  int year,base;
  string name;
  
  bool operator < (const P &a)const{
    if(year != a.year){
      return year < a.year;
    }
    else{
      return base < a.base;
    }
  }

  P(int y = 0,int b = 0,string s = "") : year(y),base(b),name(s){}

};

int main(){
  int N,Q,b,y;
  string str;


  while(cin >> N >> Q){
    vector<P> v;

    for(int i = 0 ; i < N ; i++){
      cin >> str >> b >> y;
      v.push_back(P(y,b,str));
    }

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

    int in,len = (int)v.size();
    for(int i = 0 ; i < Q ; i++){
      cin >> in;
      for(int j = 0 ; j < len ; j++){
	if(in <= v[j].year){
	  if(v[j].year-v[j].base < in){
	    cout << v[j].name << " " << in-(v[j].year-v[j].base) << endl;
	  }
	  else{
	    cout << "Unknown" << endl;
	  }
	  break;
	}
      }
    }
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <tuple>

using namespace std;

typedef tuple<string, int, int> T;

int main() {
  while (true) {
    int n, q;
    cin >> n >> q;
    
    if (n + q == 0) {
      break;
    }

    vector<T> db(n);

    for (int i = 0; i < n; i++) {
      string str;
      int a, b;
      cin >> str >> a >> b;
      db[i] = T(str, a, b);
    }

    for (int i = 0; i < q; i++) {
      int x;
      cin >> x;
      bool ok = false;
      for (int j = 0; j < n; j++) {
        int t = x - (get<2>(db[i]) - get<1>(db[i]));
        if (t > get<1>(db[i])) {
          continue;
        }
        if (t > 0) {
          cout << get<0>(db[i]) << " " << t << endl;
          ok = true;
          break;
        }
      }
      if (!ok) {
        cout << "Unknown" << endl;
      }
    }

  }
  return 0;
}