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

typedef struct{
  string name;
  int start;
  int goal;
} Data;

bool operator<(const Data &d1,const Data &d2){
  return (d1.start < d2.start);
}

int main(){
  int n,q;
  while(cin>>n>>q,n){
    vector<Data> vec(n);
    for(int i=0;i<n;i++){
      Data d;
      int diff;
      cin>>d.name>>diff>>d.goal;
      d.start=d.goal-diff+1;
      vec[i]=d;
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<q;i++){
      int num;
      cin>>num;
      if(vec[n-1].goal < num){
	cout<<"Unknown"<<endl;
	continue;
      }
      for(int j=0;j<n;j++){
	if(vec[j].start <= num){
	  if(num <= vec[j].goal){
	    cout<<vec[j].name<<" "<<num-vec[j].start+1<<endl;
	    break;
	  }
	}else{
	  cout<<"Unknown"<<endl;
	  break;
	}
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <sstream>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;

int eras,query;
struct Eras
{
  string name;
  int start,end,eraend;
  Eras(string _name,int p,int _end)
  {
    name=_name;
    end=_end;
    eraend=p;
    start=end-p+1;
  }
};

int main(int argc,char const* argv[])
{
  while(1)
    {
      cin >> eras >> query;
      if(!eras) break;
      vector<Eras> e;
      e.clear();
      for(int i=0;i<eras;i++)
	{
	  string s;
	  int a,b;
	  cin >> s >> a >> b;
	  e.push_back(Eras(s,a,b));
	}
      for(int i=0;i<query;i++)
	{
	  int ques;
	  bool ok=false;
	  cin >> ques;
	  for(int i=0;i<eras;i++)
	    {
	      if(e[i].start <= ques && ques<=e[i].end)
		{
		  cout << e[i].name << ' ' << (e[i].eraend-(e[i].end-ques)) << endl;
		  ok=true;
		  break;
		} 
	    }
	  if(!ok) cout << "Unknown" << endl;
	}
    }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
int n,q;
string str[1001];
int e[1001],w[1001];

int main(void){
	while(1){
		scanf("%d %d",&n,&q);
		if(n+q==0)break;
		for(int i=0;i<n;i++){
			cin >> str[i] >> e[i] >> w[i];
		}
		for(int i=0;i<q;i++){
			int y;
			scanf("%d",&y);
			int j;
			for(j=0;j<n;j++){
				if(w[j]-e[j]<y && y<=w[j]){
					cout << str[j] << " " << y-(w[j]-e[j]) << endl;
					break;
				}
			}
			if(j==n)cout << "Unknown" << endl;
		}
	}
	return 0;
}