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 <map>
#include <string>
#include <iostream>
using namespace std;
struct er{
    string gengo;
    int start;
    int end;
};

int main(){
    int N,Q,i,f,t,y;
    string buf;
    while(1){
        map<int,er> mp;
        cin >> N >> Q;
        if(!N && !Q){break;}
        for(i=0;i<N;i++){
            cin >> buf >> f >> t;
            struct er e={buf,t-f+1,t};
            mp[t-f+1]=e;
        }
        for(i=0;i<Q;i++){
            cin >> y;
            auto itr=mp.upper_bound(y);
            if(mp.size()>1){
                itr--;
            }
            if(itr->second.start <= y && itr->second.end >= y){
                cout << itr->second.gengo << " " << y-itr->first+1 << endl;
            }
            else{
                cout << "Unknown" <<endl;
            }
        }
    }
    return 0;
}

C++: #include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n,q,era[1000],we[1000];
char nm[1000][20];


int main()
{
	while(scanf("%d%d",&n,&q),n)
	{
		rep(i,n)scanf("%s%d%d",nm+i,era+i,we+i);
		rep(i,q)
		{
			int y; scanf("%d",&y);
			rep(j,n)if(we[j]-era[j]<y&&y<=we[j])
			{
				printf("%s %d\n",nm[j],y-we[j]+era[j]);
				goto END;
			}
			puts("Unknown"); END:;
		}
	}
	return 0;
}

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

class state{
public:
  string str;
  int n,year;
};

int main(){
  int n,m;
  while(cin >> n >> m && n && m){
    vector<state> v;
    for(int i=0;i<n;i++){
      state s;
      cin >> s.str >> s.n >> s.year;
      v.push_back(s);
    }
    for(int i=0;i<m;i++){
	int a;
	cin >> a;
	int j;
	for(j=0;j<n;j++){
	  if(v[j].year - v[j].n < a && a <= v[j].year){
	    cout << v[j].str << " " << v[j].n - (v[j].year - a) << endl;
	    break;
	  }
	}
	if(j == n) cout << "Unknown" << endl;
      }
	  }
    return 0;
  }

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 RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --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 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 SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

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

int main() {
    int N, M;
    while (cin >> N >> M, N|M) {
        vector<pair<pii, string>> Q;
        REP(i, N) {
            string s;
            int era, western;
            cin >> s >> era >> western;
            Q.push_back({{western, era}, s});
            if (era > 1) {
                Q.push_back({{western-era+1, 1}, s});
            }
            Q.push_back({{western-era, 0}, s});
        }
        SORT(Q);
        REP(i, M) {
            int q;
            cin >> q;
            bool found = false;
            FOR(i, 1, SZ(Q)) {
                if (q == Q[i-1].first.first && Q[i-1].first.second == 0) {
                    cout << "Unknown" << endl;
                    found = true;
                    break;
                } else if (Q[i-1].first.first <= q && q < Q[i].first.first) {
                    int d = q - Q[i-1].first.first;
                    cout << Q[i-1].second << " " << Q[i-1].first.second + d << endl;
                    found = true;
                    break;
                }
            }
            if (!found) {
                cout << "Unknown" << endl;
            }
        }
    }
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };


int main() {

more:;
  int n, q; cin >> n >> q;
  if (!n && !q) return 0;

  vector<tuple<int, int, string>> memo;

  rep (i, n) {
    string s; int b, c; cin >> s >> b >> c;
    memo.push_back(make_tuple(c - b + 1, c, s));
  }
  sort(all(memo));

  rep (i, q) {
    int m; cin >> m;
    bool f = true;
    for (auto&pr : memo) {
      if (get<0>(pr) <= m && m <= get<1>(pr)) {
        cout << get<2>(pr) << ' '
          << (m - get<0>(pr) + 1)
          <<endl;
        f = false;
        break;
      }
    }
    if (f) cout << "Unknown" << endl;
  }

  goto more;
}