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 <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q, _e, _w, _q;
    string _s;
    while(cin >> N >> Q && N){
        map<int, string> cvt;
        map<int, int> cvt2;
        int start, last;
        rep(i, N){
            cin >> _s >> _e >> _w;
            cvt[_w] = _s;
            cvt2[_w] = _w - _e;
            if(i == 0) start = _w - _e + 1;
            if(i == N - 1) last = _w;
        }
        rep(i, Q){
            cin >> _q;
            if(_q < start || last < _q)
              cout << "Unknown" << endl;
            else{
                auto lb = cvt.lower_bound(_q);
                string sa = lb->second;
                int ia = _q - cvt2[lb->first];
                if(ia >= 1)
                  cout << sa << ' ' << ia << endl;
                else
                  cout << "Unknown" << endl;
            }
        }
    }
    return 0;
}

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

int N,Q;

void solve() {

    map<int,string> data;
    rep(i,N) {
        string ss;
        int a,b;
        cin>>ss>>a>>b;
        data[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>
#include<stack>

#include<string>
#include<map>
using namespace std;

int main(){
  int N,Q;
  string eraname;
  int basedy,westy;
  while(cin >> N >> Q && (N!=0 || Q!=0)){
    string nams[10010];
    int begin[N],end[N];
    for(int i=0;i<N;i++){
      cin >> eraname >> basedy >> westy;
      nams[i]=eraname;
      begin[i]=westy-basedy;
      end[i]=westy;
    }
    for(int i=0;i<Q;i++){
      cin >> westy;
      for(int j=0;j<N;j++){
	if(westy > begin[j] && westy <=end[j]){
	  cout << nams[j] << " " <<  westy-begin[j] <<endl;
	  break;
	}
	if(j==N-1){
	  cout << "Unknown" << endl;
	}
      }
    }
  }

}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2242

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

vector<tuple<int, int, string>> V;
int N, Q;

int main() {
  while (cin >> N >> Q && N) {
    V.clear();
    for (int i=1; i<=N; i++) {
      string en;
      int eby, wy;
      cin >> en >> eby >> wy;
      int fy = wy - eby + 1;
      V.push_back(make_tuple(fy, -1*wy, en));
    }
    V.push_back(make_tuple(-1, 1, "dummy"));
    sort(V.begin(), V.end());
    for (int i=0; i<Q; i++) {
      int q;
      cin >> q;
      int ind = V.size()-1;
      for (unsigned int i=0; i<V.size(); i++) {
	int temp = get<0>(V[i]);
	if (temp > q) {
	  ind = i-1;
	  break;
	}
      }
      if (-1 * get<1>(V[ind]) >= q) {
	cout << get<2>(V[ind]) << " " << q - get<0>(V[ind]) + 1 << endl;
      } else {
	cout << "Unknown" << endl;
      }
    }
  }
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, q;
        cin >> n >> q;
        if(n == 0)
            return 0;

        vector<string> name(n);
        vector<int> base(n), western(n);
        for(int i=0; i<n; ++i)
            cin >> name[i] >> base[i] >> western[i];

        for(int i=0; i<q; ++i){
            int a;
            cin >> a;
            bool unknown = true;
            for(int j=0; j<n; ++j){
                if(western[j] - base[j] + 1 <= a && a <= western[j]){
                    cout << name[j] << ' ' << (a - (western[j] - base[j])) << endl;
                    unknown = false;
                }
            }

            if(unknown)
                cout << "Unknown" << endl;
        }
    }
}

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

int main(){

  for(int n,q;cin>>n>>q,n;){
    vector <pair<string, pair<int, int >>> era;

    for(int i=0;i<n;++i){
      string a;int b,c;
      cin>>a>>b>>c;
      era.push_back(make_pair(a,make_pair(c-b+1,c)));
    }

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

      for(int j=0;j<n;++j){
        if(era[j].second.first<=query&&era[j].second.second>=query){
          cout << era[j].first << " " << query-era[j].second.first+1 << endl;
          break;
        }

        if(j==q-1) cout << "Unknown" << endl;
      }
    }
  }

  return 0;
}

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

int main() {
	int n, q;
	while (cin >> n >> q, n) {
		map<int, string>mp;
		map<string, int>m;
		rep(i, n) {
			string s;
			int j, k;
			cin >> s >> j >> k;
			mp[k - j] = s;
			m[s] = j;
		}
		rep(i, q) {
			int d; cin >> d;
			auto it = mp.lower_bound(d);
			it--;
			if (it == --mp.begin()) {
				cout << "Unknown" << endl;
				continue;
			}
			if (d - (*it).first > m[(*it).second]) {
				cout << "Unknown" << endl;
				continue;
			}
			cout << (*it).second << ' ' << d - (*it).first << endl;
		}
	}
}