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<vector>
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

void solve(int q,vector<string> &a,vector<int> &b,vector<int> &c){
  rep(i,a.size()){
    int f = c[i]-b[i]+1;
    if (f <= q && q <= c[i]){
      cout <<a[i] <<" " << q-f+1 << endl;
      return;
    }
  }
  cout <<"Unknown" << endl;
}

main(){
  int n,q;
  while(cin>>n>>q && n){
    vector<string> a(n);
    vector<int> b(n),c(n);
    rep(i,n)cin>>a[i]>>b[i]>>c[i];
    rep(i,q){
      int p;cin>>p;solve(p,a,b,c);
    }
  }
}

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

using namespace std;

using pii = pair<int, int>;

int N, Q;

void solve()
{
	vector<pair<pii, string> > data;

	for(int i = 0; i < N; ++i) {
		string name;
		int b, westernY;
		cin >> name >> b >> westernY;
		data.emplace_back(pii(westernY - b + 1, westernY), name);
	}

	while (Q--) {
		int y; cin >> y;
		
		bool ok = false;

		for (int i = 0; i < N; ++i) {
			pii interval = data[i].first;
			if (interval.first <= y and y <= interval.second) {
				cout << data[i].second << ' ' << y-interval.first + 1 << '\n';
				ok = true;
				break;
			}
		}

		if (not ok) {
			cout << "Unknown\n";
		}
	}
}

int main()
{
	while (1) {
		cin >> N >> Q;
		if (N == 0 and Q == 0) break;
		solve();
	}
}

C++: #include<iostream>
using namespace std;

struct Data{

  string name;
  int b_year;
  int w_year;
  
};

int main(){

  int N,Q;
  Data list[1000];
  
  while(1){
    
    cin >>N>>Q;
    if(N==0 && Q==0)break;
    
    for(int i=0 ; i < N ; i++){
      cin >>list[i].name>>list[i].b_year>>list[i].w_year;
    }
    
    int year;
    
    for(int i=0 ; i < Q ; i++){
      cin >>year;
      bool flag=true;
      for(int j=0 ; j < N ; j++){
	if(year > list[j].w_year-list[j].b_year && year <= list[j].w_year){
	  cout <<list[j].name<<" "<<list[j].b_year-(list[j].w_year-year)<<endl;
	  flag=false;
	  break;
	}
      }
      if(flag)cout <<"Unknown"<<endl;
    }
    
  }
  return 0;
}

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

struct P {
  int start, end;
  string name;

  P(int s, int e, string n) : start(s), end(e), name(n) { }
};

bool operator < (P a, P b) {
  return a.start != b.start ? a.start < b.start : a.end < b.end;
}

int main() {
  for(int N, Q; cin >> N >> Q && N; ) {
    vector<P> ps;

    for(int i = 0; i < N; i++) {
      int west, japan;
      string name;

      cin >> name >> japan >> west;

      ps.push_back(P(west - japan + 1, west, name));
    }

    sort(ps.begin(), ps.end());

    for(int i = 0; i < Q; i++) {
      int year;
      cin >> year;

      string answer = "Unknown";

      for(int j = 0; j < N; j++) {
        if(ps[j].start <= year && year <= ps[j].end) {
          answer = ps[j].name;
          year = year - ps[j].start + 1;
          break;
        }
      }

      if(answer == "Unknown") {
        cout << answer << endl;
      } else {
        cout << answer << " " << year << endl;
      }
    }
  }
}

C++: #include<iostream>
#include<stack>

#include<string>
#include<map>
using namespace std;

int main(){
  int N,Q;
  string eraname;
  int basedy,westy;
  while(cin >> N >> Q && (N!=0 || Q!=0)){
    string nams[10010];
    int begin[N],end[N];
    for(int i=0;i<N;i++){
      cin >> eraname >> basedy >> westy;
      nams[i]=eraname;
      begin[i]=westy-basedy;
      end[i]=westy;
    }
    for(int i=0;i<Q;i++){
      cin >> westy;
      for(int j=0;j<N;j++){
	if(westy > begin[j] && westy <=end[j]){
	  cout << nams[j] << westy-begin[j] <<endl;
	  break;
	}
	if(j==N-1){
	  cout << "Unknown" << endl;
	}
      }
    }
  }

}

C++: #include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for(int i = (int)(n - 1); i >= 0; --i)
#define RFOR(i, a, b) for(int i = (int)(b - 1); i >= (int)(a); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)
#define BIT(x, i) (((x) >> (i)) & 1)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef vector<vll> vvll;

struct P {
  string name;
  int begin, end;

  bool operator <(const int& y) const {
    return end < y;
  }
};

int main() {
  int n, p;
  while(cin >> n >> p, n) {
    vector<P> database(n);
    REP(i, n){
      int y;
      cin >> database[i].name >> y >> database[i].end;
      database[i].begin = database[i].end - y + 1;
    }
    REP(i, p){
      int y;
      cin >> y;
      auto it = lower_bound(ALL(database), y);
      // LOG("%s %d ~ %d\n", it->name.c_str(), it->begin, it->end);
      if (it == database.end() || it->begin > y)
        cout << "Unknown" << endl;
      else
        printf("%s %d\n", it->name.c_str(), y - it->begin + 1);
    }
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
string S[9999],U;int n,a,b,c,d,p[9999][2],i,j;
int main(){
while(1){
cin>>a>>b;if(!a){break;}
for(i=0;i<a;i++){
n=0;cin>>U>>c>>d;
S[i]=U;
p[i][0]=d-c+1;
p[i][1]=d;
}
for(i=0;i<b;i++){
cin>>c;
for(j=0;j<a;j++){
if(c>=p[j][0] && c<=p[j][1]){
cout<<S[j]<<' '<<c-p[j][0]+1<<endl;
goto E;
}
}
printf("Unknown\n");
E:;
}
}
}

C++: #include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#define llint long long

using namespace std;
//typedef pair<llint, llint> P;
typedef pair<llint, string> P;

llint n, Q;
string s[1005];
llint x[1005], y[1005];
vector<P> vec;

int main(void)
{
	while(1){
		cin >> n >> Q;
		if(n == 0 && Q == 0) break;
		
		for(int i = 1; i <= n; i++) cin >> s[i] >> x[i] >> y[i];
		
		llint q;
		for(int i = 1; i <= Q; i++){
			cin >> q;
			for(int j = 1; j <= n; j++){
				if(q >= y[j]-x[j]+1 && q <= y[j]){
					cout << s[j] << " " << x[j]-(y[j]-q) << endl;
					goto end;
				}
			}
			cout << "Unknown" << endl;
			end:;
		}
	}
	
	return 0;
}