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 <map>
using namespace std;

int N, Q;

int main() {

	while ( cin >> N >> Q && N ) {

		map<int,string> start;
		map<string,int> finish;
		string name;

		for ( int i = 0; i < N; i++ ) {

			int local, western;

			cin >> name >> local >> western;

			start[western - local + 1] = name;

			if ( finish[name] < western ) {

				finish[name] = western;

			}

		}

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

			int western;

			cin >> western;

			bool ok = false;

			for ( map<int,string>::iterator s = start.begin(); s != start.end(); s++ ) {

				if ( s->first <= western && finish[s->second] >= western ) {

					cout << s->second << " " << western - s->first + 1 << endl;
					ok = true;
					break;

				}

			}

			if ( ! ok ) {

				cout << "Unknown" << endl;

			}

		}

	}

}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

struct Era {
  string name;
  int y, gy;
};

vector<Era> era;

int main() {
  int n, q;
  while (true) {
    cin >> n >> q;
    if (n == 0 && q == 0) break;
    era.clear();
    rep (i, n) {
      Era e;
      cin >> e.name >> e.y >> e.gy;
      era.push_back(e);
    }
    rep (i, q) {
      int y;
      cin >> y;
      rep (j, n) {
	if (era[j].gy - era[j].y < y && y <= era[j].gy) {
	  cout << era[j].name << " " << y - (era[j].gy - era[j].y) << endl;
	  goto end;
	}
      }
      cout << "Unknown" << endl;
    end:;
    }
  }
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#define F first
#define S second
using namespace std;
typedef pair<int,int> Pos;
typedef pair<Pos,string> P;
vector<P> era;
bool cmp(const P &p,const P &q){
  if(p.F.F != q.F.F)return p.F.F > q.F.F;
  return p.F.S > q.F.S;
}

bool Search(int year){
  for(int i=0;i<era.size();i++){
     if(era[i].F.F < year)break;
    if(era[i].F.S < year && year <= era[i].F.F){
      cout << era[i].S << " " << year-era[i].F.S << endl;
      return true;
    }
  }
  return false;
}

int main(){
  int N,Q,que;
  string s;
  P p;

  while(cin >> N >> Q && N && Q){
    era.clear();
    for(int i=0;i<N;i++){
      cin >> p.S >> p.F.S >> p.F.F;
      p.F.S = p.F.F-p.F.S;
      era.push_back(p);
    }
    sort(era.begin(),era.end(),cmp);


    for(int i=0;i<Q;i++){
      cin >> que;
      if(!Search(que))cout << "Unknown" << endl;
    }


  }
  return 0;
}

C++: #include <cstdio>
using namespace std;

typedef struct
{
	char name[128];
	int base;
	int western;
} ERA;

ERA era[2000];

int main()
{
	int N, Q;
	
	while (scanf("%d %d", &N, &Q), N + Q){
		for (int i = 0; i < N; i++){
			scanf("%s %d %d", &era[i].name, &era[i].base, &era[i].western);
		}
		
		for (int i = 0; i < Q; i++){
			int y;
			scanf("%d", &y);
			
			bool f = false;
			for (int j = 0; j < N; j++){
				if (y <= era[j].western && era[j].western - y < era[j].base){
					printf("%s %d\n", era[j].name, era[j].base - era[j].western + y);
					break;
				}
			}
			
			if (!f){
				puts("Unknown");
			}
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

typedef pair<int, int> P;

int main(){
  int n, m;
  while(cin >> n >> m){
    if(n == 0 && m == 0) break;
    map<string, P> era;
    string e;
    int a, b;
    for(int i = 0 ; i < n ; i++){
      cin >> e >> a >> b;
      era[e] = P(b-a, b);
    }

    for(int i = 0 ; i < m ; i++){
      cin >> a;
      bool f = false;
      for(map<string, P>::iterator it = era.begin() ; it != era.end() ; it++){
	if(it->second.first < a && a <= it->second.second){
	  cout << it->first << ' ' << a-it->second.first << endl;
	  f = true;
	  break;
	}
      }
      if(!f) cout << "Unknown" << endl;
    }
  }
  return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define repit(i,a) for(__typeof((a).begin()) i=(a).begin();i!=(a).end();i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main()
{
    int N, Q;
    while(cin >> N >> Q, N || Q){
	string str;
	int n, m;
	vi years;
	map<int,pair<int,string> > name;
	rep(i,N){
	    cin >> str >> n >> m;
	    years.pb(m);
	    name[m] = mp(n,str);
	}
	sort(all(years));
	rep(i,Q){
	    int y;
	    cin >> y;
	    if(name.find(y) != name.end()) cout << name[y].second << ' ' << name[y].first << endl;
	    else{
		vi::iterator itr = lower_bound(all(years),y);
		if(itr == years.end()) cout << "Unknown\n";
		else{
		    if(*itr < y || *itr - name[*itr].first >= y){
			cout << "Unknown\n";
		    }
		    else cout << name[*itr].second << ' ' << name[*itr].first - *itr + y << endl;
		}
	    }
	}
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
//int dy[] = {0, 0, -1, 1};
//int dx[] = {1, -1, 0, 0};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k, q;
    while (cin >> k >> q && k) {
        vector<pair<pair<string, int>, int> > v;
        rep(i, k) {
            string a; int b, c;
            cin >> a >> b >> c;
            v.push_back({{a, b}, c});
        }
        using psii = pair<pair<string, int>, int>;
        sort(v.begin(), v.end(), [](const psii& x, const psii& y){return x.second < y.second;});
        rep(i, q) {
            int a; cin >> a;
            
            rep(j, v.size()) {
                if (a <= v[j].second) {
                    
                    int b = v[j].second - a;
                    if (v[j].first.second - b > 0) {
                        cout << v[j].first.first << " " << v[j].first.second - b << endl;
                    } else {
                        cout << "Unknown" << endl;
                    }
                    break;
                }
                if (j == v.size() - 1) {
                    cout << "Unknown" << endl;
                }
            }
            
        }
    }
}