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 <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;

    for(int i = 0 ; i < Q ; i++){
      bool found = false;

      cin >> in;
      for(int j = 0 ; j < N ; 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;
	    found = true;
	    break;
	  }
	}
      }

      if(!found) cout << "Unknown" << endl;
    }
  }

  return 0;
}

C++: #include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long int lli;


int main(void) {
    while(1) {
        vector<pair<lli,string>> dict;
        map<string,lli> max;
        int n,q;
        cin >> n >> q;
        if(!n) break;

        for(int i=0; i<n; i++) {
            string name;
            lli base, west;
            cin >> name >> base >> west;
            dict.push_back(pair<lli,string>(west-base+1, name));
            max[name] = base;
        }
        for(int i=0; i<q; i++) {
            lli y;
            cin >> y;
            auto it = upper_bound(begin(dict), end(dict), pair<lli,string>(y, string("\xFF")));

            if(it == dict.end())
                it = dict.begin() + (dict.size()-1);
            else if(it == dict.begin()) {
                cout << "Unknown" << endl;
                continue;
            }
            else
                it--;

            if((y-it->first+1) > max[it->second])
                cout << "Unknown" << endl;
            else
                cout << it->second << ' ' << y-(it->first)+1 << 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<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

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

C++: #include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<iostream>

using namespace std;


int main(void) {
    while(1) {
        map<int,string> dict;
        map<string,int> max;
        int n,q;
        cin >> n >> q;
        if(!n) break;

        auto last = dict.begin();
        for(int i=0; i<n; i++) {
            string name;
            int base, west;
            cin >> name >> base >> west;
            dict[west-base+1] = name;
            max[name] = base;
            if(last->first > west-base+1)
                last = dict.find(west-base+1);
        }
        for(int i=0; i<q; i++) {
            int y;
            cin >> y;
            auto it = dict.upper_bound(y);
            if(it == dict.end())
                it = last;
            else if(it == dict.begin()) {
                cout << "Unknown" << endl;
                continue;
            }
            else
                it--;

            if((y-it->first+1) > max[it->second])
                cout << "Unknown" << endl;
            else
                cout << it->second << ' ' << y-(it->first)+1 << endl;
        }

    }
    return 0;
}

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

using i64 = int64_t;

int main(){
    int n, q;
    while(cin >> n >> q, n != 0){
        map<string, pair<int, int>> mp;
        for(int i=0;i<n;++i){
            string name;
            int era, western;
            cin >> name >> era >> western;
            mp[name].first = western - era + 1;
            mp[name].second = max(mp[name].second, western);
        }
        for(int i=0;i<q;++i){
            int q;
            cin >> q;
            bool found = false;
            pair<string, int> ans;
            for(auto e: mp){
                if(e.second.first <= q && e.second.second >= q){
                    found = true;
                    ans.first = e.first;
                    ans.second = q - e.second.first + 1;
                    break;
                }
            }
            if(found){
                cout << ans.first << " " << ans.second << endl;
            }else{
                cout << "Unknown" << endl;
            }
        }
    }

    return 0;
}