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 <functional>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

struct D{
    int ey, wy;
    string s;
    D(){};
    D(int _ey, int _wy, string _s) {ey=_ey, wy=_wy, s=_s;};
    bool operator<(const D& rhs) {
        return wy < rhs.wy;
    }
};
int n, q;
int y[1010];

int b_serch(int l, int r , int num) {
    int c = (l+r)/2;
    if (y[c] == num) return c;
    else if (y[c] > num) return b_serch(c, r, num);
    else return b_serch(l,c,num);
}

int main(void){
    while (1) {
        cin >> n >> q;
        if (!n && !q) break;
        vector<D> data(n);
        int _ey, _wy;
        string _s;
        D _data;
        for (int i = 0; i < n; i++) {
            cin >> _s >> _ey >> _wy;
            D _data(_ey, _wy, _s);
            y[i] = _wy;
            data[i] = _data;
        }
        sort(y, y+n);
        sort(data.begin(), data.end());
        
        for (int i = 0; i < q; i++) {
            int x; cin >> x;
            int *it = lower_bound(y, y+n, x);
            //cout << *it << endl;
            int idx;
            if (y[0] == *it) idx = 0;
            else if (y[n-1] == *it) idx = n-1;
            else idx = b_serch(0, n-1, *it);
            //cout << idx << endl;
            
            int ini = data[idx].wy - data[idx].ey;
            if (x > ini && x <= data[idx].wy) 
                cout << data[idx].s << " " << x - ini << endl;
            else
                cout << "Unknown" << endl;
        }
    }
    
    return 0;
}

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

struct Y{
  string n; int b,e;
  Y(void){}
  Y(string a,int x,int y):n(a),b(x),e(y){}
  bool operator<(const Y a)const{return b<a.b;}
};

int main(){
  int n,q,i;
  int a,b,y,l,r,m;
  string name;
  Y e[1010];

  std::ios::sync_with_stdio(false);
  while(cin >> n >> q, n+q){
    for(i=0;i<n;i++){
      cin >> name >> a >> b;
      e[i] = Y(name,b-a+1,b);
    }
    sort(e,e+n);
    for(i=0;i<q;i++){
      cin >> y;
      l=-1,r=n;
      while(r-l>1){
	m = (l+r)/2;
	if(e[m].e>=y)r = m;
	else l = m;
      }

      if(r==n || e[r].b>y)cout << "Unknown\n";
      else cout << e[r].n << " " << y-e[r].b+1 << endl;
    }
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q, _e, _w, _q;
    string _s;
    while(cin >> N >> Q && N){
        map<int, string> cvt;
        map<int, int> cvt2;
        rep(i, N){
            cin >> _s >> _e >> _w;
            cvt[_w] = _s;
            cvt2[_w] = _w - _e;
        }
        rep(i, Q){
            cin >> _q;
            auto lb = cvt.lower_bound(_q);
            pair<string, int> ans;
            ans.first = lb->second;
            ans.second = _q - cvt2[lb->first];
            if(ans.second >= 1)
              cout << ans.first << ' ' << ans.second << endl;
            else
              cout << "Unknown" << endl;
        }
    }
    return 0;
}

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

class Era
{
public:
	string n;
	int s,y;

	Era()
	{}

	Era(string n, int y, int s)
		:n(n),y(y),s(s)
	{}
};

int main()
{
	int N,Q;
	while(cin >> N >> Q, (N||Q)) {
		Era era[1005];

		for(int i=0; i<N; i++) {
			string n;
			int y,s;
			cin >> n >> y >> s;
			era[i] = Era(n, y, s - y);
		}

		while(Q--) {
			bool f = false;
			int y;
			cin >> y;

			for(int i=0; i<N; i++) {
				if(y > era[i].s && y <= era[i].s + era[i].y) {
					f = true;
					cout << era[i].n << " " << y - era[i].s << endl;
					break;
				}
			}

			if(!f) {
				cout << "Unknown" << endl;
			}

		}
	}
}

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

using namespace std;

int main()
{
    int n, m;
    
    while (scanf("%d %d", &n, &m) && n){
        string names[1024];
        int D[1024], S[1024];
        
        for (int i = 0; i < n; i++){
            char tmp[128];
            scanf("%s %d %d", tmp, D + i, S + i);
            names[i] = (string)tmp;
        }
        
        for (int i = 0; i < m; i++){
            int x;
            bool f = false;
            scanf("%d", &x);
            for (int j = 0; j < n; j++){
                if (S[j] - D[j] + 1 <= x && x <= S[j]){
                    f = true;
                    printf("%s %d\n", names[j].c_str(), x - S[j] + D[j]);
                }
            }
            if (!f) printf("Unknown\n");
        }
    }
    
    return (0);
}

C++: #define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int N, Q; cin >> N >> Q;
		if (N == 0 && Q == 0) break;
		vector<string> s(N);
		vector<ll> a(N), b(N);
		for (int i = 0; i < N; i++)
			cin >> s[i] >> a[i] >> b[i];
		while (Q--) {
			ll x; cin >> x;
			bool flag = false;
			for (int i = 0; i < N; i++) {
				if (x >= b[i] - a[i] + 1 && x <= b[i]) {
					cout << s[i] << ' ' << x - (b[i] - a[i]) << endl;
					flag = true;
					break;
				}
			}
			if (!flag) cout << "Unknown" << endl;
		}
	}
}