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++: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

int main(){
  int N,Q;
  while(~scanf("%d %d",&N,&Q)){
    if(N==0 && Q==0) break;

    map<string,int> StartWestYear;
    map<int,string> StartWestYearName;
    map<string,int> EraBasedYearUpperBounds;
    vector<int> WesternBasedYears;
    for(int i=0;i<N;i++){
      string EraName;
      int EraBasedYear,WesternYear;
      cin >> EraName >> EraBasedYear >> WesternYear;
      StartWestYear[EraName] = WesternYear - EraBasedYear + 1;
      StartWestYearName[WesternYear - EraBasedYear + 1] = EraName;

      EraBasedYearUpperBounds[EraName] = max(EraBasedYear,EraBasedYearUpperBounds[EraName]);
      WesternBasedYears.push_back(WesternYear - EraBasedYear + 1);
    }

    WesternBasedYears.push_back(0);
    WesternBasedYears.push_back(INF);
    sort(WesternBasedYears.begin(),WesternBasedYears.end());

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

      string res = "Unknown";
      for(int year_idx=0;year_idx+1 < WesternBasedYears.size();year_idx++){

	// year := 2000
	// [1990(year_idx's year) ~ 2050)
	if(WesternBasedYears[year_idx] <= year && year < WesternBasedYears[year_idx+1]){
	  if(year_idx == 0) break;

	  if(StartWestYearName.find(WesternBasedYears[year_idx]) != StartWestYearName.end()){
	    ostringstream oss;

	    if(EraBasedYearUpperBounds[StartWestYearName[WesternBasedYears[year_idx]]]
	       < year - WesternBasedYears[year_idx] + 1) break;

	    oss << (StartWestYearName[WesternBasedYears[year_idx]])
		<< " " 
		<< (year - WesternBasedYears[year_idx] + 1);
	    res = oss.str();
	    break;
	  }
	}
      }

      printf("%s\n",res.c_str());
    }
  }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_Q = 1000;

/* typedef */

struct Era {
  string name;
  int sy, ey;

  Era() {}
  Era(int _y): sy(_y) {}

  bool operator<(const Era& e) const { return sy < e.sy; }
};

/* global variables */

int n, q;
Era eras[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> q;
    if (n == 0) break;

    for (int i = 0; i < n; i++) {
      int ey, gy;
      cin >> eras[i].name >> ey >> gy;
      eras[i].sy = gy - ey + 1;
      eras[i].ey = gy;
    }
    sort(eras, eras + n);
    //for (int i = 0; i < n; i++)
    //cout << eras[i].name << ' ' << eras[i].sy << '-' << eras[i].ey << endl;
    
    while (q--) {
      int ey, gy;
      cin >> gy;

      int eid = upper_bound(eras, eras + n, Era(gy)) - eras - 1;
      //printf("%d -> %d\n", gy, eid);

      if (eid < 0 || eras[eid].ey < gy)
	cout << "Unknown" << endl;
      else {
	int ey = gy - eras[eid].sy + 1;
	cout << eras[eid].name << ' ' << ey << endl;
      }
    }
  }

  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n,q;
	while(cin>>n>>q&&!(n==0&&q==0))
	{
		//各年号の元年を入れる
		pair<ll,string> a[1000];
		REP(i,n){
			int x,y;string s;
			cin >> s>>x>>y;
			a[i]=make_pair(y-x+1,s);
		}
		//各元号の初年度を昇順に整列
		sort(a,a+n);
		
		REP(i,q)
		{
			bool flag(false);
			ll age;cin>>age;
			
			if(age<a[0].first){cout<<"Unknown"<<endl;}
			else if(age>=a[n-1].first){cout<<a[n-1].second<<" "<<age-a[n-1].first+1<<endl;}
			else
			{
				REP(j,n-1)
				{
					if(a[j].first<=age&&a[j+1].first>age)
					{
						cout<<a[j].second<<" "<<age-a[j].first+1<<endl;flag=true;break;
					}
				}
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

struct node {
	int s, e;
	string name;
};
bool operator<(const node& lhs, const node& rhs) {
	return lhs.s < rhs.s;
}

int main() {
	int n, q;
	while(cin >> n >> q, n||q) {
		vector<node> vn;
		rep(i, n) {
			node in;
			int era;
			cin >> in.name >> era >> in.e;
			in.s = in.e - era + 1;
			vn.push_back(in);
		}
		sort(vn.begin(), vn.end());
		rep(i, q) {
			int y;
			cin >> y;
			bool found = false;
			rep(j, n) {
				if(vn[j].s<=y && y<=vn[j].e) {
					cout << vn[j].name << ' ' << y-vn[j].s+1 << endl;
					found = true;
					break;
				}
			}
			if(!found) {
				cout << "Unknown" << endl;
			}
		}
	}
	return 0;
}

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

struct era{
  long long int western;
  long long int based;
  string name;
};

int main()
{
  for(;;){
    struct era data[1000];
    int n,q;
    long long int year;
    struct era *e;
    e=data;
    cin>>n>>q;
    if(!(n|q)) break;
    for(int i=0;i<n;i++)
      cin>>(e+i)->name>>(e+i)->based>>(e+i)->western;
    for(int i=0;i<n-1;i++)
      for(int j=0;j<n-1;j++)
	if((e+j)->western>(e+j+1)->western){
	  int tmp1=(e+j)->western;
	  (e+j)->western=(e+j+1)->western;
	  (e+j+1)->western=tmp1;
	  int tmp2=(e+j)->based;
	  (e+j)->based=(e+j+1)->based;
	  (e+j+1)->based=tmp2;
	  string tmp3=(e+j)->name;
	  (e+j)->name=(e+j+1)->name;
	  (e+j+1)->name=tmp3;
	}
    for(int i=0;i<q;i++){
      int jud=0;
      cin>>year;
      for(int j=0;j<n;j++){
	if((e+j)->western-(e+j)->based+1<=year&&year<=(e+j)->western){
	  jud=1;
	  cout<<(e+j)->name<<" "<<year-(e+j)->western+(e+j)->based<<endl;
	}
      }
      if(!jud) cout<<"Unknown"<<endl;
    }
  }
}