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

C++: #include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};


int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0) break;
		vs a(n);
		vi b(n),c(n);
		for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
		for(int i=0;i<m;i++){
			int x;
			cin>>x;
			bool B=0;
			for(int j=0;j<n;j++){
				if(x>c[j]-b[j]&&x<=c[j]){
					cout<<a[j]<<' '<<x-c[j]+b[j]<<endl;
					B=1;
				}
			}
			if(!B) cout<<"Unknown"<<endl;
		}
	}
}

C++: // AOJ 0029 English Sentence
// ??????0??????????£? 5???
// map????????£?????°???????????????????????§???????????????????????¬??????????????????????¢?????????????
#include <iostream>
#include <map>
#include <string>
using namespace std;
int N,Q;
string era[10010];
int eby[10010],wy[10010];
int solve(){
	cin >> N >> Q;
	if(N+Q==0)return 1;
	for(int i=0;i<N;i++){
		cin >> era[i] >> eby[i] >> wy[i];
	}
	for(int i=0;i<Q;i++){
		int tar;
		cin >> tar;
		bool known = false;
		for(int j=0;j<N;j++){
			if(wy[i]-eby[i]<tar&&tar<=wy[i]){
				cout << era[i] << ' ' << tar-(wy[i]-eby[i]) << endl;
				known = true;
				break;
			}
		}
		if(!known)cout << "Unknown" << endl;
	}
	return 0;
}
int main(){
	while(!solve()){}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

struct Era {
  string name;
  int base;
  int western;
  Era(string name, int base, int western) :
    name(name), base(base), western(western) {}
  bool valid(int year){
    return (western - base < year && year <= western);
  }
  void show(int year){
    cout << name << " " << base + year - western << endl;
  }
};

int main()
{
  int N, Q;
  while (N = in(), Q = in(), N || Q){
    vector<Era> eras;
    for (int i = 0; i < N; i++){
      string name;
      int base, western;
      cin >> name >> base >> western;
      eras.emplace_back(name, base, western);
    }
    while (Q--){
      bool ok = false;
      int year = in();
      for (auto& era : eras){
        if (era.valid(year)){
          era.show(year);
          ok = true;
          break;
        }
      }
      if (!ok) puts("Unknown");
    }
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <climits>
using namespace std;
 
int N, Q;
struct Year {
  string name;
  int base, wy;
  Year() {}
  Year(string name, int base, int wy)
    : name(name), base(base), wy(wy) {}
  bool operator < (const Year &y) const {
    if(wy != y.wy) return wy < y.wy;
    if(base != y.base) return base < y.base;
    return name < y.name;
  }
};
 
vector<Year> v;
int main() {
  while(cin >> N >> Q && (N || Q)) {
    v.clear();
    for(int i = 0; i < N; ++i) {
      Year y;
      cin >> y.name >> y.base >> y.wy;
      y.wy = y.wy - y.base + 1;
      v.push_back(y);
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < Q; ++i) {
      int q;
      cin >> q;
      int p  = distance(v.begin(),lower_bound(v.begin(), v.end(), Year("",INT_MAX,q)));
      if(p == 0 || !(q < v[p-1].wy+v[p-1].base)) cout << "Unknown" << endl;
      else cout << v[p-1].name << " " << q-v[p-1].wy+1 << endl;
    }
  }
  return 0;
}