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 <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
  
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
  
using namespace std;
  
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

struct era{
    string name;
    int start;
    int end;
    era(string n, int s, int e):name(n),start(s),end(e){}
    bool include(int n){
        if(start < n && n <= end) return true;
        return false;
    }
};

int main(){
    int n, q;
    while(cin >> n >> q, n|q){
        vector<era> v;
        rep(i, n){
            string name;
            int period, end;
            cin >> name >> period >> end;
            v.push_back(era(name, end-period, end));
        }
        rep(i, q){
            int year;
            cin >> year;
            int ans = -1;
            rep(j, v.size()){
                if(v[j].include(year)){
                    ans = j;
                    break;
                }
            }
            if(ans != -1) cout << v[ans].name << ' ' << year-v[ans].start << endl;
            else cout << "Unknown" << endl;
        }

    }

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

int n, q;

class node
{
public:
	string name;
	int start, end;

	node(string n, int a, int b):name(n), start(b-a+1), end(b){}

	bool is_in_range(int year)
	{
		return start <= year && year <= end;
	}
};

int main(void)
{
	while(cin >> n >> q, n|q) {
		vector<node> vs;
		rep(i, n) {
			string name;
			int erabased, westernyear;
			cin >> name >> erabased >> westernyear;
			vs.push_back(node(name, erabased, westernyear));
		}

		rep(i, q) {
			int year;
			cin >> year;
			int cnt = 0, idx = -1;
			rep(j, vs.size()) {
				if(vs[j].is_in_range(year)) {
					idx = j;
					cnt++;	
				}
			}
			if (cnt != 1)
				printf("Unknown\n");
			else
				printf("%s %d\n", vs[idx].name.c_str(), year-vs[idx].start+1);
		}
	}
	return 0;
}

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

struct Q {
	int b, e;
	string name;
	Q(int b = 0, int e = 0, string name = string()): b(b), e(e), name(name){}
};

int main()
{
	int n, q;
	while (scanf("%d %d", &n, &q), n|q){
		vector<Q> v;
		for (int i = 0; i < n; i++){
			string str;
			int b, w;
			cin >> str >> b >> w;
			v.push_back(Q(w - b, w, str));
		}
		while (q--){
			int y;
			scanf("%d", &y);
			bool f = false;
			for (int i = 0; i < n; i++){
				Q& a = v[i];
				if (y <= a.b || a.e < y) continue;
				cout << a.name << " " << y - a.b << endl;
				f = true;
				break;
			}
			if (!f) puts("Unknown");
		}
	}
}

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

int N, Q;
struct Year {
  string name;
  int base, wy;
  Year() {}
  Year(string name, int base, int wy)
    : name(name), base(base), wy(wy) {}
  bool operator < (const Year &y) const {
    if(wy != y.wy) return wy < y.wy;
    if(base != y.base) return base < y.base;
    return name < y.name;
  }
};

vector<Year> v;
int main() {
  while(cin >> N >> Q && (N || Q)) {
    v.clear();
    for(int i = 0; i < N; ++i) {
      Year y;
      cin >> y.name >> y.base >> y.wy;
      y.wy = y.wy - y.base + 1;
      v.push_back(y);
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < Q; ++i) {
      int q;
      cin >> q;
      int p  = distance(v.begin(),lower_bound(v.begin(), v.end(), Year("",INT_MAX,q)));
      if(p == 0 || !(q < v[p-1].wy+v[p-1].base)) cout << "Unknown" << endl;
      else cout << v[p-1].name << " " << q-v[p-1].wy+1 << endl;
    }
  }
  return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	for(int n, q; cin >> n >> q, n;) {
		vector<string> name(n);
		vector<int> based(n), western(n);
		for(int i = 0; i < n; ++i)
			cin >> name[i] >> based[i] >> western[i];

		for(int i = 0; i < q; ++i) {
			int year;
			cin >> year;

			for(int i = 0; i < n; ++i)
				if(western[i] - based[i] < year && year <= western[i]) {
					cout << name[i] << " " << year - western[i] + based[i] << endl;
					goto next;
				}

			cout << "Unknown" << endl;

		next:;
		}
	}

	return EXIT_SUCCESS;
}