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<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n, q;
	while (cin >> n >> q, n) {
		map<int, string>mp;
		map<string, int>m;
		rep(i, n) {
			string s;
			int j, k;
			cin >> s >> j >> k;
			mp[k - j] = s;
			m[s] = j;
		}
		rep(i, q) {
			int d; cin >> d;
			auto it = mp.lower_bound(d);
			it--;
			if (it == --mp.begin()) {
				puts("Unknown");
				continue;
			}
			if (d - (*it).first > m[(*it).second]) {
				puts("Unknown");
				continue;
			}
			cout << (*it).second << ' ' << d - (*it).first << endl;
		}
	}
}

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

struct data{int start,end;};
int main()
{
  int N,Q;
  string name;
  int year;
  string s;
  int a,b;
  data d;
  map<string,data> m;
  map<string,data>::iterator it;
  while(cin>>N>>Q,N|Q){
    m.clear();
    while(N-->0){
      cin>>s>>a>>b;
      d.end=b;
      d.start=b-a+1;
      m[s]=d;
    }
    while(Q-->0){
      name="Unknown";
      year=0;
      cin>>a;
      for(it=m.begin();it!=m.end();it++){
	if(a < it->second.start || it->second.end < a)continue;
	year = a - it->second.start + 1;
	name = it->first;
      }
      cout<<name;
      if(name!="Unknown")cout<<" "<<year;
      cout<<endl;
    }
  }
}

C++: #include <iostream>
#include <vector>
#include <tuple>

using namespace std;

int main()
{
	for(int n,q;cin>>n>>q,n|q;){
		vector<tuple<string,int,int>> ys;
		for(int i=0;i<n;i++){
			string name; int year,ad;
			cin>>name>>year>>ad;
			ys.emplace_back(name,ad-year+1,ad);
		}
		
		while(q--){
			int y; cin>>y;
			int i=-1;
			for(int j=0;j<n;j++)
				if(get<1>(ys[j])<=y && y<=get<2>(ys[j])){
					i=j;
					break;
				}
			if(i==-1)
				cout<<"unknown"<<endl;
			else
				cout<<get<0>(ys[i])<<' '<<y-get<1>(ys[i])+1<<endl;
		}
	}
	
	return 0;
}

C++: ////////////////////////////////////////
///  tu3 pro-con template            ///
////////////////////////////////////////
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <regex>
using namespace std;

//// MACRO ////
#define countof(a) (sizeof(a)/sizeof(a[0]))

#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define RFOR(i,s,n) for (int i = (n)-1; i >= (s); i--)
#define pos(c,i) c.being() + (i)
#define allof(c) c.begin(), c.end()
#define aallof(a) a, countof(a)
#define partof(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define apartof(a,i,n) a + (i), a + (i) + (n)
#define long long long

#define EPS 1e-9
#define INF (1L << 30)
#define LINF (1LL << 60)

#define PREDICATE(t,a,exp) [&](const t & a) -> bool { return exp; }
#define COMPARISON_T(t) bool(*)(const t &, const t &)
#define COMPARISON(t,a,b,exp) [&](const t & a, const t & b) -> bool { return exp; }
#define CONVERTER(TSrc,t,TDest,exp) [&](const TSrc &t)->TDest { return exp; }

inline int sign(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); }

//// i/o helper ////

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
struct _Writer { bool f; _Writer() : f(false) { } template <class T> _Writer operator ,(const T &rhs) { cout << (f ? " " : "") << rhs; f = true; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__
#define WRITE(...) _Writer(), __VA_ARGS__; cout << endl

template <class T> struct vevector : public vector<vector<T>> { vevector(int n = 0, int m = 0, const T &initial = T()) : vector<vector<T>>(n, vector<T>(m, initial)) { } };
template <class T> struct vevevector : public vector<vevector<T>> { vevevector(int n = 0, int m = 0, int l = 0, const T &initial = T()) : vector<vevector<T>>(n, vevector<T>(m, l, initial)) { } };
template <class T> struct vevevevector : public vector<vevevector<T>> { vevevevector(int n = 0, int m = 0, int l = 0, int k = 0, const T &initial = T()) : vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) { } };
template <class T> T read() { T t; cin >> t; return t; }
template <class T> vector<T> read(int n) { vector<T> v; REP(i, n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i, n) v.push_back(read<T>(m)); return v; }
template <class T> vevector<T> readjag() { return read<T>(read<int>()); }
template <class T> vevector<T> readjag(int n) { vevector<T> v; REP(i, n) v.push_back(readjag<T>()); return v; }

template <class T1, class T2> inline istream & operator >> (istream & in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; }
template <class T1, class T2> inline ostream & operator << (ostream &out, pair<T1, T2> &p) { out << p.first << p.second; return out; }
template <class T> inline ostream & operator << (ostream &out, vector<T> &v)
{
	ostringstream ss;
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	out << s.substr(0, s.length() - 1) << endl;
	return out;
}

//// start up ////
void solve();
int main()
{
	solve();
	return 0;
}


void solve()
{
	int testcases = INF;
	REP(testcase, testcases)
	{
		READ(int, N, Q);
		if (!(N | Q)) break;
		map<long, pair<string, long>> m;
		REP(i, N)
		{
			READ(string, eraName);
			READ(long, era, western);
			long f = western - era + 1;
			m[f] = make_pair(eraName, max(m[f].second, era));
		}

		REP(i, Q)
		{
			READ(long, q);
			auto it = m.upper_bound(q);
			if (it == m.begin()) { WRITE("Unknown"); }
			else
			{
				it--;
				long x = q - it->first + 1;
				if (x <= it->second.second)
				{
					WRITE(it->second.first, x);
				}
				else
				{
					WRITE("Unknown");
				}
			}
		}
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n, q;
	while (scanf("%d%d", &n, &q), n) {
		map<int, string>mp;
		rep(i, n) {
			string s;
			int j, k;
			cin >> s >> j >> k;
			mp[k - j] = s;
		}
		rep(i, q) {
			int d; scanf("%d", &d);
			auto it = mp.lower_bound(d);
			it--;
			if (it == --mp.begin()) {
				puts("Unknown");
				continue;
			}
			if (it != --mp.end()) {
				if ((*++it).first == d) {
					puts("Unknown");
					continue;
				}
				it--;
			}
			cout << (*it).second << ' ' << d - (*it).first << endl;
		}
	}
}