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 <cstring>
#include <cstdio>
#include <cstring>

using namespace std;

char s[100010];
int len ;
int pos[20]= {0,0,1,2,0,1,2,0,1,2};

int dp[2][10][10][2];
int cost(int x,int y) {
    if(x == 5 || y == 5) return 0;
    if(pos[x] - pos[y] > 0) return 1;
    return 0;
}
int main() {
    freopen("/home/lovezzt/桌面/in.txt", "r", stdin);
    while(1) {
        scanf("%s",s);
        if (s[0] == '#') break;
        len = strlen(s);
        memset(dp[0],60,sizeof(dp[0]));
        dp[0][5][5][0] = dp[0][5][5][1] = 0;
        bool p = 0,q = 1;
        for(int i = 0; i < len ; ++i) {
            memset(dp[q],60,sizeof(dp[q]));
            for(int j = 0; j < 10; ++j) {
                for(int k = 0; k < 10 ; ++k) {
                    for(int l = 0; l < 2; ++l) {
                        if(dp[p][j][k][l] > len) continue;
                        int pos = s[i] - '0';
                        if(l == 0) {
                            dp[q][ pos ][ k ][0] = min(dp[q][ pos ][ k ][0] , dp[p][j][k][l] + 1 +  cost( pos ,k));
                            dp[q][ j ][ pos ][1] = min(dp[q][ j ][ pos ][1] , dp[p][j][k][l] + cost(j , pos));
                        } else {
                            dp[q][ pos ][k][0] = min(dp[q][ pos ][k][0] , dp[p][j][k][l] + cost(pos , k) );
                            dp[q][ j ][ pos ][1] = min(dp[q][ j ][ pos ][1] , dp[p][j][k][l] + 1 + cost(j , pos));
                        }
                    }
                }
            }
            p = q;
            q = !q;
        }
        int ans = 0x3fffffff;
        for(int j = 0; j < 10; ++j) {
            for(int k = 0; k < 10 ; ++k) {
                for(int l = 0; l < 2; ++l) {
                    ans = min( dp[p][j][k][l] ,ans);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
struct era{
  ll s,e;
  string name;
  bool operator<(const era&e)const{
    return s < e.s;
  }
};
int main(){
  ll n,q;
  int i,j,k;
  era e;
  string str;
  ll b,w;
  cin >> n >> q;
  while(n+q!=0){
    vector<era> v;
    for(i=0;i<n;i++){
      cin >> str >> b >> w;
      e.name=str;
      e.s=w-b+1;e.e=w;
      //cout << e.s << " " << e.e  << endl;
      v.push_back(e);
    }
    sort(v.begin(),v.end());
    for(i=0;i<q;i++){
      cin >> b;
      ll st=0,en=v.size()-1,no;
      no=(st+en)/2;
      for(j=0;j<100;j++){
	if(v[no].s<=b) st = no;
	else en=no;
	no=(st+en)/2;
      }
      //cout << v[no].s << " " << v[no].e  << endl;
      if(v[no].s<=b&&b<=v[no].e) cout << v[no].name <<" "<<  (b-v[no].s+1) << endl;
      else cout << "Unknown" << endl;
    }
    
    cin >> n >> q;
  }
  return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
template<class T> using vv=vector< vector<T> >;
typedef deque<int> di;
typedef deque< deque<int> > ddi;


int main() {
    while(1) {
        map<string, i_i> M;
        int n,q;
        cin >> n >> q;
        if(n==0) break;
        rep(i,n) {
            string s;
            int e,w;
            cin >> s >> e >> w;
            M[s] = make_pair(w-e, max(M[s].second,e));
        } 

        rep(i,q) {
            int w;
            bool f = false;
            cin >> w;
            for(auto itr = M.begin(); itr != M.end(); ++itr) {
                if(itr->second.first < w && (itr->second.first + itr->second.second) >= w) {
                    cout << itr->first << w - itr->second.first << endl;
                    f = true;
                    break;
                } 
            }
            if(!f) cout << "Unknown" << endl;
        }
    }
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int N, Q;

struct Era {
	string name;
	int ey, gy;
};
bool operator < (const Era& e1, const Era& e2) {
	return e1.gy < e2.gy;
}

vector<Era> v;

void solve(int y) {
	int p = N;
	for (int i = 0; i < N - 1; i++) {
		if (v[i].gy <= y && y < v[i + 1].gy) {
			p = i;
			break;
		}
	}
	
	if (p == N) {
		if (y < v[0].gy) {
			if (y < v[0].gy - v[0].ey) cout << "Unknown" << endl;
			else cout << v[0].name << " " << v[0].ey - (v[0].gy - y) << endl;
		}
		else if (y > v[N - 1].gy) {
			cout << "Unknown" << endl;
		}
		else {
			cout << v[N - 1].name << " " << v[N - 1].ey + (y - v[N - 1].gy) << endl;
		}
	} else {
		if (v[p + 1].gy - v[p + 1].ey + 1 > y) {
			if (v[p].gy < y) cout << "Unknown" << endl;
			else cout << v[p].name << " " << v[p].ey + (y - v[p].gy) << endl;
		} else {
			cout << v[p + 1].name << " " << v[p + 1].ey + (y - v[p + 1].gy) << endl;
		}
	}
}

int main() {
	while (cin >> N >> Q, N) {
		v.clear();
		for (int i = 0; i < N; i++) {
			string name; int ey, gy;
			cin >> name >> ey >> gy;
			v.push_back((Era){name, ey, gy});
		}
		sort(v.begin(), v.end());
		
		for (int i = 0; i < Q; i++) {
			int y; cin >> y;
			solve(y);
		}
	}
	
	return 0;
}