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 <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <ctime>
#include <climits>
#include <cassert>
#include <cmath>
#include <string>
#include <bitset>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#define Fill(a, b) memset(a, b, sizeof(a))
#define Copy(a, b) memcpy(a, b, sizeof(b))
#define NPOS string::npos
#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 erep(j, a) for (Tedge *j = a; j; j = j -> next)
#define irep(i,a) for (__typeof(a.begin()) i = a.begin(); i != a.end(); i++)
#define sqr(a) ((a) * (a))
#define sf scanf
#define pf printf
#define pb push_back
#define ppb pop_back
#define pft push_front
#define ppf pop_front
#define mp make_pair
#define vec vector
#define it iterator
#define fir first
#define sec second
#define x first
#define y second
#define all(a) a.begin(),a.end()
#define sz(a) (int)(a.size())
#define bg(a) (a).begin()
#define en(a) (a).end()
#define clr(a) (a).clear()
#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define bin_cnt(x) __builtin_popcount((unsigned)x)
#define gcd(a, b) __gcd(a, b)
using namespace std;
template<class T> inline bool gmin(T &a, T b) { if (a > b) return a = b, true; return false; }
template<class T> inline bool gmax(T &a, T b) { if (a < b) return a = b, true; return false; }
template<class T> T exgcd(T a, T b, T &x, T &y) { if (!b) return x = (T)1, y = (T)0, a; else { T d = exgcd(b, a % b, y, x); return y -= a / b * x, d; } }
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vec<int> vi;
typedef vec<double> vd;
typedef istringstream iss;
typedef ostringstream oss;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = 1e10;
const double EPS = 1e-9;
const double PI = 3.14159265358979323846264338327950288;
inline int dcmp(const double &a) { return a > EPS ? 1 : (a < -EPS ? -1 : 0); }

const int MAXN = 1005;

int n, q;
pii era[MAXN];
char s[MAXN][20];

int main() {
    while (sf("%d %d", &n, &q), n + q) {
        rep (i, 1, n) {
            int a, b;
            sf("%s %d %d", s[i], &a, &b);
            era[i] = mp(b - a + 1, b);
        }
        rep (i, 1, q) {
            int y;
            sf("%d", &y);
            bool flag = false;
            rep (i, 1, n) if (y >= era[i].fir && y <= era[i].sec) {
                pf("%s %d\n", s[i], y - era[i].fir + 1);
                flag = true;
                break;
            }
            if (!flag) pf("Unknown\n");
        }
    }
	return 0;
}

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

int main()
{
	int N, Q;
	while (cin >> N >> Q && N != 0 || Q != 0)
	{
		string names[1000];
		long eraBased[1000];
		long yearStart[1000];
		long western[1000];

		for (int i = 0; i < N; i++)
		{
			cin >> names[i] >> eraBased[i] >> western[i];
			yearStart[i] = western[i] - eraBased[i];
		}

		for (int i = 0; i < Q; i++)
		{
			long year;
			cin >> year;
			string yearName = "";
			int diff = -1;
			for (int j = 0; j < N; j++)
			{
				if (yearStart[j] < year && western[j] >= year)
				{
					yearName = names[j];
					diff = (year - yearStart[j]);
					break;
				}
			}

			if (diff != -1)
			{
				cout << yearName << " " << diff << endl;
			}
			else
			{
				cout << "Unknown" << endl;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
#define INF 1000000000000LL
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<long, long> pll;
typedef pair<pll, string> pls;

int N, Q, Y, W;
string Name;
pls E[1000];

int main(void) {
  while(cin >> N >> Q, N || Q) {
    REP(i, 0, N) {
      cin >> Name >> Y >> W;
      E[i] = pls(pll(W - Y + 1, Y), Name);
    }

    sort(E, E + N);

    REP(i, 0, Q) {
      int q; cin >> q;
      if(q < E[0].fi.fi) {
        cout << "Unknown" << endl;
        continue;
      }
      REP(j, 0, N - 1) {
        if(E[j].fi.fi <= q && q < E[j + 1].fi.fi) {
          int ans = q - E[j].fi.fi + 1;
          if(ans <= E[j].fi.se) cout << E[j].se << " " << ans << endl;
          else cout << "Unknown" << endl;
          break;
        }
      }
    }
  }
  return 0;
}

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;

			if (query <= year[0] - based[0] || query > year[N - 1]) {
				goto End;
			}

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

	return 0;
}