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++: # define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,-1,1,0 }, dy[4] = { 1,0,0,-1 };

vector< pair<pii, string> > a;
int main()
{
	int n, q;
	while (cin >> n >> q&&n)
	{
		a.clear();
		FOR(i, n)
		{
			string s;
			int x, y;
			cin >> s >> x >> y;
			a.push_back(make_pair(pii(y - x, y), s));
		}
		FOR(i, q)
		{
			int x; cin >> x;
			bool ok = false;
			FOR(j, n)
			{
				if (a[j].first.first + 1 <= x&&x <= a[j].first.second)
				{
					cout << a[j].second << " " << x - a[j].first.first << endl;
					ok = true;
					break;
				}
			}
			if (!ok)
			{
				cout << "Unknown" << endl;
			}
		}
	}

}

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

int main() {
  int n, q, era[1000], west[1000];
  string name[1000];
  
  while( cin >> n >> q && (n|q) ) {
    for(int i=0; i<n; i++) {
      cin >> name[i] >> era[i] >> west[i];
    }
    
    for(int i=0; i<q; i++) {
      int year;
      int f = 0;
      cin >> year;
      for(int j=0; j<n; j++) {
	if( west[j] - era[j] < year
	    && year <= west[j] ) {
	  cout << name[j] << " " << year - west[j] + era[j] << endl;
	  f = 1;
	  break;
	}
      }
      if(!f) cout << "Unknown" << endl;
    }
    
  }
  
  return 0;
}

C++: #include <string>
#include <iostream>
using namespace std;
int N, Q, v[1000], w[1000], x; char s[1000][20];
int main() {
	while (scanf("%d %d", &N, &Q), N | Q) {
		for (int i = 0; i < N; i++) scanf("%s%d%d", s[i], &v[i], &w[i]);
		for (int i = 0; i < Q; i++) {
			scanf("%d", &x); int f = 0;
			for (int j = 0; j < N; j++) {
				if (w[j] - v[j] < x && x <= w[j]) {
					printf("%s %d\n", s[j], x - w[j] + v[j]); f = 1; break;
				}
			}
			if (!f) cout << "Unknown" << endl;
		}
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;
#define debug2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define debugg(g,h,w) rep(i,0,h) { rep(j,0,w) cout << g[i][j] << " "; cout << endl;}
#define debugv(v) for(auto&& x : v){cout << x << " ";} cout << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;
typedef pair<ll, ll> Pll;

struct era{
	string name;
	int s;
	int e;
	era(){};
	era(string _n, int _s, int _e) {name = _n, s = _s, e = _e;};
	bool operator<(const era& rhs) {
		return e < rhs.e;
	}
};
struct b {
	bool operator ()(era const& ms, int i) {
		return ms.e < i;
	}
};
era a[1010];

int main()
{
	while (1) {
		int n, q;
		cin >> n >> q;
		if (!n && !q) break;
		memset(a, 0, sizeof(a));

		rep(i,0,n) {
			string name;
			int s, e;
			cin >> name >> s >> e;
			a[i] = {name,s,e};
		}
		sort(a, a+n);
		//rep(i,0,n) cout << a[i].name << endl;

		rep(i,0,q) {
			int x;
			cin >> x;
			auto *p = lower_bound(a, a+n, x, b());
			int check = a[p-a].e - x;
			if (p-a < n && check < a[p-a].s) cout << a[p-a].name << " " << a[p-a].s-check << endl;
			else 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 (scanf("%d%d", &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; scanf("%d", &d);
			auto it = mp.lower_bound(d);
			it--;
			if (it == --mp.begin()) {
				puts("Unknown");
				continue;
			}
			if (d - (*it).first > m[(*it).second]) {
				puts("Unknown");
				continue;
			}
			cout << (*it).second << ' ' << d - (*it).first << endl;
		}
	}
}

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

int main()
{
	while (true) {
		int N, Q;
		cin >> N >> Q;

		if (N == 0 && Q == 0) {
			break;
		}

		vector<string> names(N);
		vector<int> based(N);
		vector<int> year(N);

		for (int i = 0; i < N; i++) {
			cin >> names[i] >> based[i] >> year[i];
		}


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

			string ans_str;
			int ans_year = -1;

			for (int j = 0; j < N; j++) {
				for (int k = 0; k < based[j]; k++) {
					if (year[j] - k == query) {
						ans_str = names[j];
						ans_year = based[j] - k;
						goto End;
					}
				}
			}
		End:
			if (ans_year == -1) {
				cout << "Unknown" << endl;
			}
			else {
				cout << ans_str << " " << ans_year << endl;
			}
		}
	}

	return 0;
}