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;

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<ll,P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-8;

constexpr int MAX_A = 7368792;

bool solve(){
    int n, q;
    cin >> n >> q;
    if(n == 0) return true;
    vector<pair<int,string> > v;
    vector<P> cnt;
    for(int i=0;i<n;i++){
        string en;
        int ey, wy;
        cin >> en >> ey >> wy;
        v.emplace_back(make_pair(wy-ey+1,en));
        cnt.emplace_back(P(wy-ey+1,1));
        cnt.emplace_back(P(wy+1,-1));
    }
    sort(v.begin(), v.end());
    sort(cnt.begin(), cnt.end());
    cnt.emplace_back(P(INF,0));
    for(int i=0;i<int(cnt.size())-1;i++){
        cnt[i+1].second += cnt[i].second;
    }
    for(int i=0;i<q;i++){
        int y;
        cin >> y;
        if(y < v[0].first || (--lower_bound(cnt.begin(),cnt.end(),P(y+1,0)))->second != 1){
            cout << "Unknown" << endl;
            continue;
        }
        auto p = --upper_bound(v.begin(), v.end(), make_pair(y,string("~")));
        cout << p->second << " " << y-p->first+1 << endl;
    }
    return false;
}

int main(){
    while(!solve());
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
using namespace std;
#define rep(i, b) for( int i = 0; i < b; i++ )

struct era{
    string name;
    int end, year;
};

int main(){
    int n, q;
    while( cin >> n >> q, n ){
        vector<era> eras(n);
        //vector<int> list(1<<9);
        //rep(i, list.size()) list[i] = i;
        rep(i, n){
            //string name;
            //int end, year;
            cin >> eras[i].name >> eras[i].end >> eras[i].year;
        }
        rep(i, q){
            int query;
            cin >> query;
            int ans = 0;
            rep(j, n){
                if( eras[j].year - eras[j].end < query && query <= eras[j].year ){
                    ans = query - eras[j].year + eras[j].end;
                    cout << eras[j].name << ' ' << ans << endl;
                    break;
                }
            }
            if( ans == 0 ) cout << "Unknown" << endl;
        }
    }
}

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;
        }
        sort(begin(dict),end(dict));
        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 <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std;



int main(){

	int n,q;
	while(cin>>n>>q,n||q){

		vector<string> era(n);
		vector<long long> a(n),b(n);

		for(int i=0;i<n;i++){
			cin>>era[i]>>a[i]>>b[i];
		}


		while(q--){
			long long y;
			cin>>y;

			
			bool ok=false;
			for(int i=0;i<n-1;i++){
				if( b[i]-a[i]+1<=y && y<=b[i] ){
					ok=true;
					cout<<era[i]<<" "<<y-b[i]+a[i]<<endl;
				}
			}
			
			if(!ok)cout<<"Unknown"<<endl;
		}
	}

	return 0;
}

C++: #include <stdio.h>
#include <algorithm>
#define inf 1000000111
#define N 1005

using namespace std;

struct Calender
{
     int l, r;
     char st[22];
}cale[N];

int cmp(Calender x, Calender y)
{
     return x.l < y.l;
}

int main()
{
     int n, q, x;
     while(scanf("%d%d", &n, &q))
     {
          if(n == 0 && q == 0)
          {
               break ;
          }
          for(int i = 0; i < n; i++)
          {
               scanf("%s%d%d", cale[i].st, &x, &cale[i].r);
               cale[i].l = cale[i].r - x;
          }
          sort(cale, cale + n, cmp);
          cale[n].l = inf;

          while(q--)
          {
               scanf("%d", &x);
               for(int i = 0; i <= n; i++)
               {
                    if(cale[i].l >= x)
                    {
                         if(i > 0 && cale[i - 1].l < x && cale[i - 1].r >= x)
                         {
                              printf("%s %d\n", cale[i - 1].st, x - cale[i - 1].l);
                         }
                         else
                         {
                              printf("Unknown\n");
                         }
                         break ;
                    }
               }
          }
     }
     return 0;
}

C++: #include<cstdio>
#include<climits>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
struct S{int b,e;string s;}s;
int C(S l,S r){return l.b<r.b;}
int main()
{
	int N,Q;
	char _[32];
	typedef vector<S>V;
	V v;
	V::iterator i;
	v.reserve(1002);
	while(scanf("%d%d",&N,&Q),N)
	{
		v.clear();
		s.b=s.e=-1;
		v.push_back(s);
		while(N--)
		{
			scanf("%s%d%d",&_,&s.b,&s.e);
			s.b=s.e-s.b+1;
			s.s=_;
			v.push_back(s);
		}
		s.b=s.e=INT_MAX;
		v.push_back(s);
		sort(v.begin(),v.end(),C);
		while(Q--)
		{
			scanf("%d",&N);
			s.b=N;
			i=lower_bound(v.begin(),v.end(),s,C);
			if(i->b==N)printf("%s 1\n",i->s.c_str());
			else if(i[-1].b<=N&&N<=i[-1].e)
				printf("%s %d\n",i[-1].s.c_str(),N-i[-1].b+1);
			else puts("Unknown");
		}
	}
	return 0;
}