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

struct era{
  era(){name="";s=0;e=0;};
  era(string str,int a,int b){
    name=str;
    s=a;
    e=b;
  }
  string name;
  int s,e;
};

bool operator<(era a,era b){
  return a.s<b.s;
}

int n,q;
vector<era> eras;
void init(){
  n=q=0;
  eras.resize(0);
}
bool input(){
  cin>>n>>q;
  return n!=0||q!=0;
}

bool input_era(){
  string str;
  int a,b;
  for(int i=0;i<n;i++){
    cin>>str>>a>>b;
    eras.push_back(era(str,b-a+1,b));
  }
  sort(eras.begin(),eras.end());
}

era serch(int n){
  for(int i=0;i<eras.size();i++){
    if(eras[i].s<=n&&n<=eras[i].e){
      return eras[i];
    }
  }
  return era("Unknown",-100,-100);
}


void solve(){
  for(int i=0;i<q;i++){
    int qu;
    cin>>qu;
    era ans=serch(qu);
    if(ans.s==ans.e){
      cout<<ans.name<<endl;
    }else{
      cout<<ans.name<<" "<<qu-ans.s+1<<endl;
    }
  }
}

int main(){
  while(init(),input()){
    input_era();
    solve();
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,string> P;
typedef pair<int,P > PP;

int main(){
  int n,q;
  while(cin>>n>>q,n){
    PP pr[1000];
    for(int i=0;i<n;i++){
      string s;
      int a,b;
      cin>>s>>a>>b;
      pr[i]=PP(b,P(a,s));
    }
    sort(pr,pr+n);
    for(int i=0;i<q;i++){
      int x;
      cin>>x;
      int ok=n-1,ng=-1,mid;
      while(ok-ng>1){
	mid=(ok+ng)/2;
	if(pr[mid].first>=x)ok=mid;
	else ng=mid;
      }
      int t=pr[ok].first-x;
      int k=pr[ok].second.first;
      if(t<k)cout<<pr[ok].second.second<<" "<<k-t<<endl;
      else cout<<"Unknown"<<endl;
    }
  }
    return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>

int n, q, Y;
struct node{
    char name[20];
    int p;
    int y;
    int k;
}s[1010];

int cmp(const void * a, const void * b){
    struct node * aa = (node *)a;
    struct node * bb = (node *)b;
    return ((aa->y) > (bb->y) ? 1 : -1);
}

void find(int Y){
    if(s[0].y > Y){
        printf("Unknown\n");
    }
    else{
        int pos = 0;
        for(int i=0; i<n; i++){
            if(s[i].y < Y && i >= pos) pos = i;
        }
        if(s[pos].p + Y - s[pos].y > s[pos].k) printf("Unknown\n");
        else  printf("%s %d\n", s[pos].name, s[pos].p + Y - s[pos].y);
    }

}

int main(){
    //freopen("in.txt", "r", stdin);
    while(scanf("%d %d", &n, &q), n|q){
        for(int i=0; i<n; i++){
            scanf("%s %d %d", s[i].name, &s[i].p, &s[i].y);
            s[i].y -= s[i].p-1;
            s[i].k = s[i].p;
            s[i].p = 1;
        }
        qsort(s, n, sizeof(s[0]), cmp);

        for(int i=0; i<q; i++){
            scanf("%d", &Y);
            find(Y);
        }
    }
    return 0;
}

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

int main() {
    while (true) {
        int n, q;
        cin >> n >> q;
        if ((n | q) == 0) {
            break;
        }
        map<int, pair<int, string> > eras;
        vector<int> firstYears;
        for (int i = 0; i < n; i++) {
            string eraName;
            int eraBasedYear, westernYear;
            cin >> eraName >> eraBasedYear >> westernYear;
            int firstYear = westernYear - eraBasedYear + 1;
            eras.insert(make_pair(firstYear, make_pair(westernYear, eraName)));
            firstYears.push_back(firstYear);
        }
        sort(firstYears.begin(), firstYears.end());
        for (int i = 0; i < q; i++) {
            int year;
            cin >> year;
            int firstYear = -1;
            for (int i = 0; i < n; i++) {
                if (year < firstYears[i]) {
                    if (i > 0) {
                        firstYear = firstYears[i - 1];
                    }
                    break;
                }
            }
            if (firstYear < 0 || eras[firstYear].first < year) {
                cout << "Unknown" << endl;
            } else {
                cout << eras[firstYear].second << " " << year - firstYear + 1 << endl;
            }
        }
    }
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000
using namespace std;
typedef pair<int, int> P;
typedef pair<P, string> Pi;
#define fi first
#define sec second
int main()
{
    int n, q;
    while (cin >> n >> q)
    {
        if (n == 0 && q == 0)
            break;
        string str;
        vector<Pi> vec(n + 1);
        int era[n + 1];
        int westerm[n + 1];
        rep(i, n)
        {
            cin >> str >> era[i] >> westerm[i];
            vec[i].fi.fi = westerm[i] - era[i] + 1;
            vec[i].fi.sec = westerm[i];
            vec[i].sec = str;
        }
        vector<int> year(q + 1);
        rep(i, q) cin >> year[i];
        rep(i, q)
        {
            bool flag = false;
            rep(j, n)
            {
                if (year[i] >= vec[j].fi.fi && year[i] <= vec[j].fi.sec)
                {
                    flag = true;
                    cout << vec[j].sec << " " << year[i] - westerm[j] + era[j] << endl;
                    break;
                }
            }
            if (!flag)
                cout << "Unknown" << endl;
        }
    }
    return 0;
}

C++: 
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2242

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main()
{
	int N,Q;
	
	while(cin >> N >> Q && N)
	{
		map<int, pair<string,int> > calendar;
		
		string name;
		int year_w, year_g;
		rep(nth,N)
		{
			cin >> name >> year_w >> year_g;
			for(int i=0; i<year_w; i++){
				calendar[year_g - i] = {name, year_w - i};
			}
		}

		int q;
		rep(nth, Q)
		{
			cin >> q;
			if(calendar.find(q) == calendar.end()){
				cout << "Unknown" << endl;
			}else{
				cout << calendar[q].first << " " << calendar[q].second << endl;
			}
		}
	}
	return 0;
}