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;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for(int i = (int)(n - 1); i >= 0; --i)
#define RFOR(i, a, b) for(int i = (int)(b - 1); i >= (int)(a); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)
#define BIT(x, i) (((x) >> (i)) & 1)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef vector<vll> vvll;

struct P {
  string name;
  int begin, end;

  bool operator <(const P& p) const {
    return begin < p.begin;
  }
};

int main() {
  int n, p;
  while(cin >> n >> p, n) {
    vector<P> database(n);
    REP(i, n){
      int y;
      cin >> database[i].name >> y >> database[i].end;
      database[i].begin = database[i].end - y + 1;
    }
    SORT(database);
    REP(i, p){
      int y;
      cin >> y;
      auto it = lower_bound(ALL(database), y, [](const P &p, const int &y){
        return p.end < y;
      });
      if (it == database.end() || it->begin > y)
        cout << "Unknown" << endl;
      else
        printf("%s %d\n", it->name.c_str(), y - it->begin + 1);
    }
  }
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <vector>

using namespace std;

typedef pair<int, int> P;
typedef pair<P, string> Q;

int main() {
	int n, q;
	while (cin >> n >> q) {
		if (n == 0 && q == 0) {
			break;
		}
		priority_queue<Q> pq;
		string era;
		int base;
		int west;
		for (int i = 0; i < n; i++) {
			cin >> era >> base >> west;
			Q p;
			(p.first).first = west-base+1;
			(p.first).second = west;
			p.second = era;
			pq.push(p);
		}
		vector<Q> hyou(n);
		for (int i = 0; i < n; i++) {
			hyou[i] = pq.top();
			pq.pop();
		}
		int a;
		for (int i = 0; i < q; i++) {
			cin >> a;
			bool hantei = true;
			for (int j = 0; j < n; j++) {
				if ((hyou[j].first).first <= a && a <= (hyou[j].first).second) {
					hantei = false;
					cout << hyou[j].second << ' ' << a-(hyou[j].first).first+1 << endl;
					break;
				}
			}
			if (hantei) {
				cout << "Unknown" << endl;
			}
		}
	}
	return 0;
}

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

int N,Q,EBY,WY,q; string EN,now;
map<string,pair<int,int>> calendar;
map<int,string> era;
set<int> years;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> Q,N){
        calendar.clear(); era.clear(); years.clear();
        for (int i=0;i<N;++i){
            cin >> EN >> EBY >> WY;
            if (calendar.count(EN)) calendar[EN].second=max(calendar[EN].second,WY);
            else calendar[EN]={WY-EBY+1,WY};
        }
        for (auto p:calendar){
            era[p.second.second]=p.first;
            years.insert(p.second.second);
        }
        for (;Q--;){
            cin >> q;
            auto itr=years.lower_bound(q);
            if (itr==years.end()){
                cout << "Unknown" << '\n';
                continue;
            }
            now=era[*itr];
            if (q<calendar[now].first) cout << "Unknown" << '\n';
            else cout << now << ' ' << q-calendar[now].first+1 << '\n';
        }
    }
}

C++: #include <iostream>
#include <string>
using namespace std;
 
string name[1001];
int eby[1001], wy[1001];
 
int main(){
	name[0] = "Unknown";
	int n, q;
	while(cin >> n >> q, n){
		for(int i = 0; i < n; ++i){
			cin >> name[i] >> eby[i] >> wy[i];
		}
		for(int i = 0; i < q; ++i){
			int ans = -1, x;
			cin >> x;
			for(int j = 0; j < n; ++j){
				if(x <= wy[j] && x > wy[j] - eby[j]){
					ans = j;
					break;
				}
			}
			if(ans == -1){
				cout << "Unknown\n";
			}
			else{
				cout << name[ans] << ' ' << x - wy[ans] + eby[ans] << '\n';
			}
		}
	}
}

C++: #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <cctype>
using namespace std;

#define INF 0x7fffffff
#define eps 1e-12
#define MOD 10000007
#define N 1110

struct point
{
    string name;
    int a,e;

};
point p[1005];

bool cmp(point a,point b)
{
    return a.a<b.a;
}

int main()
{
    int n,q;
    while(~scanf("%d%d",&n,&q))
    {
        int x,y;
        if(n==0&&q==0)
            break;
        for(int i=0; i<n; i++)
        {
            cin>>p[i].name;
            cin>>x>>y;
            p[i].a=y-x;
            p[i].e=y;

        }
        sort(p,p+n,cmp);
        int ans;
        int ss;
        for(int i=0; i<q; i++)
        {
            cin>>ss;
            int id=-1;
            bool k=1;
            for(int j=0; j<n; j++)
                if(p[j].a<=ss-1&&p[j].e>=ss)
                {
                    if(id!=-1)
                        k=0;
                    id=i;
                    //break;
                }
            if(id==-1)
                k=0;
            if(!k)
                printf("Unknown\n");

            else
                cout<<p[id].name<<" "<<ss-p[id].a<<endl;
        }

    }

    return 0;
}

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

int main(){
  while(1){
    int n,q,e[N],w[N],que[N],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[i];

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