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 <algorithm>
#include <iostream>
#include <string>
#define MAX_N 1000
using namespace std;

string eraname[MAX_N];
int erabased[MAX_N], western[MAX_N];
int erafirst[MAX_N];

void search(int y, int n) {
  if (y < erafirst[0]) {
    cout << "Unknown" << endl;
    return;
  }
  for (int i = 1; i < n; i++) {
    if (y < erafirst[i]) {
      int temp = y - erafirst[i - 1] + 1;
      if (temp > erabased[i - 1]) {
	cout << "Unknown" << endl;
	return;
      } else {
	cout << eraname[i - 1] << ' ' << temp << endl;
	return;
      }
    }
  }
  cout << "Unknown" << endl;
  return;
}

void era_sort(int n) {
  for (int i = 0; i < n; i++) {
    for (int j = i; j > 0; j--) {
      if (erafirst[j - 1] > erafirst[j]) {
	swap(eraname[j - 1], eraname[j]);
	swap(erabased[j - 1], erabased[j]);
	swap(erafirst[j - 1], erafirst[j]);
	swap(western[j - 1], western[j]);
      }
    }
  }
}

void init(int n) {
  for (int i = 0; i < n; i++) {
    eraname[i] = erabased[i] = western[i] = erafirst[i] = 0;
  }
}

int main() {
  while (true) {
    int n, q;
    cin >> n >> q;
    if (n == 0 && q == 0) return 0;

    init(n);
    era_sort(n);

    for (int i = 0; i < n; i++) {
      cin >> eraname[i] >> erabased[i] >> western[i];
    }

    for (int i = 0; i < n; i++) {
      erafirst[i] = western[i] - erabased[i] + 1;
    }

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

      search(query, n);
    }
  }
}

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;
        int start = INF, last = -1;
        rep(i, N){
            cin >> _s >> _e >> _w;
            cvt[_w] = _s;
            cvt2[_w] = _w - _e;
            start = min(start, _w - _e + 1);
            last = max(last, _w);
        }
        rep(i, Q){
            cin >> _q;
            if(_q < start || last < _q)
              cout << "Unknown" << endl;
            else{
                auto lb = cvt.lower_bound(_q);
                string sa = lb->second;
                int ia = _q - cvt2[lb->first];
                if(ia >= 1)
                  cout << sa << ' ' << ia << endl;
                else
                  cout << "Unknown" << endl;
            }
        }
    }
    return 0;
}

C++: 
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
string IntToString(int);
string solve(vector<pair<string,pair<int,int> > > &era,int q){
  string ans = "Unknown";
  for(int i = 0;i < era.size();i++){
    //    cout << era[i].first << "   " << era[i].second.first << " " << era[i].second.second << endl;
    if(era[i].second.first <= q && era[i].second.second >= q){
      //cout << i << endl;
      ans = era[i].first + " " + IntToString(q-era[i].second.first+1);
      return ans;
    }
  }
  return ans;
}
int main(){
  int n,q;
  while(cin >> n >> q,n && q ){
    vector<pair<string,pair<int,int> > > era(n);

    for(int i =0;i < n;i++){
      string name;
      int time,year;
      cin >> name >> time >> year;
      era[i] = pair<string,pair<int,int> >(name,pair<int,int>(year-time+1,year));
    }
    for(int i = 0;i < q;i++){
      int q_year;
      cin >> q_year;
      cout << solve(era,q_year) << endl;
    }

  }
  return 0;
}
string IntToString(int number){
  stringstream ss;
  ss << number;
  return ss.str();
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a||b){
    vector<string>in(a);
    vector<int>in1(a);
    vector<int>in2(a);
    rep(i,a)cin>>in[i]>>in1[i]>>in2[i];
    rep(q,b){
      int n;
      cin>>n;
      bool h=false;
      rep(i,a){
	if(in2[i]-in1[i]<n&&n<=in2[i]){
	  h=true;
	  cout<<in[i]<<" "<<n-in2[i]+in1[i]<<endl;
	  break;
	}
      }
      if(!h)cout<<"Unknown"<<endl;
    }
  }
}

C++: #include <stdio.h>
#include <string.h>
#define MAXNUM 1000000000

int main(void){
	int year[MAXNUM], eby, wy, n, q, i, j, query;
	char name[1000][17], c;
	while(1){
		scanf("%d%d%*c",&n,&q);
		if(n == 0 && q == 0)
			break;
		memset(year,-1,sizeof(year));
		for(i = 0;i < n;i++){
			j = 0;
			while((c = getchar()) != ' ')
				name[i][j++] = c;
			name[i][j] = '\0';
			scanf("%d%d%*c",&eby,&wy);
			wy--;
			for(j = 0;j < eby;j++)
				year[wy - j] = i;
		}
		for(i = 0;i < q;i++){
			scanf("%d%*c",&query);
			query--;
			if(year[query] != -1){
				for(j = 0; query - j > 0 && year[query - j] == year[query];j++);
				printf("%s %d\n",name[year[query]],j);
			}
			else
				printf("Unknown\n");
		}
	}
	return 0;
}

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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(a) "(" << #a << ": " << (a) << ")"

template<typename T>
void chmin(T &x, T y) { x = min(x, y); }

template<typename T>
void chmax(T &x, T y) { x = max(x, y); }

typedef long long int lli;
typedef long double ld;
typedef tuple<int,string,int> Tr;

const int INF = INT_MAX/2 - 1;
const double EPS = 1e-14;
const int dx[4] = {0, 1, 0, -1}; // {-1,  0,  1, -1, 1, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0}; // {-1, -1, -1,  0, 0,  1, 1, 1};

string solve(vector<Tr> table, int wy) {
  auto iter = lower_bound(ALL(table), make_tuple(wy, "ZZZZZZ", INF), greater<Tr>());
  if (iter == table.end()) { return "Unknown"; }
  string name; int start, limit;
  tie(start, name,limit) = *iter;
  int ey = wy - start;
  if (wy > limit) return "Unknown";
  return name + " " + to_string(ey);
}

int main() {
  cout << fixed << setprecision(10);
  int N, Q;
  while (cin >> N >> Q and N) {
    vector<Tr> table;
    REP(i, N) {
      string name; int eyear, wyear;
      cin >> name >> eyear >> wyear;
      table.emplace_back(wyear - eyear, name, wyear);
    }
    sort(ALL(table), greater<Tr>());
    REP(i, Q) {
      int wyear;
      cin >> wyear;
      cout << solve(table, wyear) << endl;
    }
  }
  return 0;
}