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 <algorithm>
#include <vector>
 
using namespace std;
 
struct P{
    int year,base;
    string name;
   
    bool operator < (const P &a)const{
	if(year != a.year){
	    return year < a.year;
	}
	else{
	    return base < a.base;
	}
    }
 
    P(int y = 0,int b = 0,string s = "") : year(y),base(b),name(s){}
 
};
 
int main(){
    int N,Q,b,y;
    string str;
 
 
    while(cin >> N >> Q){
	vector<P> v;
 
	for(int i = 0 ; i < N ; i++){
	    cin >> str >> b >> y;
	    v.push_back(P(y,b,str));
	}
 
	sort(v.begin(),v.end());
 
	int in;
 
	for(int i = 0 ; i < Q ; i++){
	    bool found = false;
 
	    cin >> in;
	    for(int j = 0 ; j < N ; j++){
		if(in <= v[j].year){ 
		    if(v[j].year-v[j].base < in){
			cout << v[j].name << " " << in-(v[j].year-v[j].base) << endl;
			found = true;
			break;
		    }
		}
	    }
	    if(!found) cout << "Unknown" << endl;
	}
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  int n,q;
  while(cin>>n>>q,n|q){
    vector<pair<string,pii> > eras(n);
    REP(i,n){
      cin>>eras[i].first;
      int ey,wy;
      cin>>ey>>wy;
      eras[i].second.first=wy-ey+1;
      eras[i].second.second=max(eras[i].second.second,wy);
    }
    REP(i,q){
      int y;
      cin>>y;
      bool ok=false;
      REP(j,n){
        if(eras[j].second.first<=y&&y<=eras[j].second.second){
          cout<<eras[j].first<<" "<<(y-eras[j].second.first+1)<<endl;
          ok=true;
          break;
        }
      }
      if(!ok){
        cout<<"Unknown"<<endl;
      }
    }
  }
}