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>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[1000],b[1000],m,n,p;
  char s[1000][17];
  while(cin>>n>>m&&n&&m){
    for(i=0;i<n;i++)
      cin>>s[i]>>a[i]>>b[i];
    for(i=0;i<m;i++){
      cin>>p;
      for(j=0;j<n;j++){
	if(b[j]-a[j]<p&&p<=b[j])
	  break;
      }
      if(j==n)
	cout<<"Unknown"<<endl;
      else
	cout<<s[j]<<" "<<a[j]-b[j]+p<<endl;
    }
  }
  return 0;
}

C++: #include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<iostream>
#include<algorithm>

using namespace std;


int main(void) {
    while(1) {
        vector<pair<int,string>> dict;
        map<string,int> max;
        int n,q;
        cin >> n >> q;
        if(!n) break;

        for(int i=0; i<n; i++) {
            string name;
            int base, west;
            cin >> name >> base >> west;
            dict.push_back(pair<int,string>(west-base+1, name));
            max[name] = base;
        }
        for(int i=0; i<q; i++) {
            int y;
            cin >> y;
            auto it = upper_bound(begin(dict), end(dict), pair<int,string>(y, string("zzz")));

            if(it == dict.end())
                it = dict.begin() + (dict.size()-1);
            else if(it == dict.begin()) {
                cout << "Unknown" << endl;
                continue;
            }
            else
                it--;

            if((y-it->first+1) > max[it->second])
                cout << "Unknown" << endl;
            else
                cout << it->second << ' ' << y-(it->first)+1 << endl;
        }

    }
    return 0;
}