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==-100&&ans.e==-100){
      cout<<ans.name<<endl;
    }else{
      cout<<ans.name<<" "<<qu-ans.s+1<<endl;
    }
  }
}
 
int main(){
  while(init(),input()){
    input_era();
    solve();
  }
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main(){
	int n, q;
	while (cin >> n >> q && n){
		vector<string> s(n);
		VI a(n), b(n);
		REP(i,n) cin >> s[i] >> a[i] >> b[i];
		while (q--){
			int x;
			cin >> x;
			bool f = 1;
			REP(i,n){
				if (x > b[i] - a[i] && x <= b[i]) {
					cout << s[i] << " " << x - b[i] + a[i] << endl;
					f = 0;
					break;
				}
			}
			if (f) cout << "Unknown" << endl;
		}
	}
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,q;
  while(1){
    cin>>n>>q;
    if(n+q==0)break;
    vector<pair<pii,string> > p(n);
    rep(i,n){
      int a,b;
      cin>>p[i].second>>a>>b;
      p[i].first.first=b-a+1;
      p[i].first.second=b;
    }
    sort(all(p));
    rep(i,q){
      int y;
      cin>>y;
      rep(j,n)
	if(p[j].first.first<=y && y<=p[j].first.second){
	  cout<<p[j].second<<" "<<y-p[j].first.first+1<<endl;
	  break;
	}
      if(j==n)cout<<"Unknown"<<endl;
    }
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

vector<pair<int, pair<int, string> > > data;

int val;

int get_era(int q){
  int tmp = -1;
  for(int i=0;i<data.size();i++){
    if(data[i].first <= q && q <= (data[i].second).first){
      val = q-data[i].first;
      return i;
    }
  }
  return -1;
}

main(){
  int N, Q;
  while(cin >> N >> Q){
    if(N == 0 && Q == 0) break;
    data.clear();
    for(int i=0;i<N;i++){
      string name;
      int era, west;
      cin >> name >> era >> west;
      data.push_back(make_pair(west-era+1, make_pair(west, name)));
    }
    sort(data.begin(), data.end());
    for(int i=0;i<Q;i++){
      int q, ans;
      cin >> q;
      ans = get_era(q);
      if(ans == -1) cout << "Unknown" << endl;
      else cout << (data[ans].second).second << ' ' << val+1 << endl;
    }
  }
  return 0;

}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main() {
  while(1){
    int n,q;
    cin>>n>>q;
    if(!n)break;
    vector<tuple<int, int, string>> v;
    REP(i,n){
      string name;
      int era, western;
      cin>>name>>era>>western;
      v.emplace_back(western, era, name);
    }
    sort(begin(v),end(v));
    REP(i,q){
      int year;
      cin>>year;
      int ue,uw;
      string un;
      tie(uw,ue,un) = *upper_bound(begin(v),end(v),make_tuple(year,0,string()));
      if (year <= uw - ue)
        cout << "Unknown" << endl;
      else
        cout << un << ' ' << ue - (uw - year) << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main() {
  while(1){
    int n,q;
    cin>>n>>q;
    if(!n)break;
    vector<tuple<int, int, string>> v;
    REP(i,n){
      string name;
      int era, western;
      cin>>name>>era>>western;
      v.emplace_back(western, era, name);
    }
    sort(begin(v),end(v));
    REP(i,q){
      int year;
      cin>>year;
      int ue,uw;
      string un;
      auto itr = upper_bound(begin(v),end(v),make_tuple(year,0,string()));
      if (itr == end(v)) {
        cout << "Unknown" << endl;
        continue;
      }
      tie(uw,ue,un) = *itr;
      if (year <= uw - ue)
        cout << "Unknown" << endl;
      else
        cout << un << ' ' << ue - (uw - year) << endl;
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define INF 1000000001
using namespace std;
typedef tuple<int, int, string> TP;

int main()
{
	int N, Q, EY,WY;
	string EN;
	while (cin >> N >> Q, N || Q) {
		vector<TP> Eras(N);
		for (int i = 0; i < N; i++) {
			cin >> EN >> EY >> WY;
			get<0>(Eras[i]) = WY - EY + 1;
			get<1>(Eras[i]) = WY;
			get<2>(Eras[i]) = EN;
		}
		sort(Eras.begin(), Eras.end());
		for (int i = 0, q; i < Q; i++) {
			cin >> q;
			auto up = upper_bound(Eras.begin(), Eras.end(), TP(q, INF, string()));
			if (up == Eras.begin() || get<0>(*(up - 1)) > q || get<1>(*(up - 1)) < q)
				cout << "Unknown" << endl;
			else
				cout << get<2>(*(up - 1)) << ' ' << (q - get<0>(*(up - 1)) + 1) << endl;
		}
	}
	return 0;
}