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 <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;
		}
		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;
}

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

int main(){

  for(int n,q;cin>>n>>q,n;){
    vector <pair<string, pair<int, int >>> era;

    for(int i=0;i<n;++i){
      string a;int b,c;
      cin>>a>>b>>c;
      era.push_back(make_pair(a,make_pair(c-b+1,c)));
    }

    for(int i=0;i<q;++i){
      int query;
      cin>>query;

      for(int j=0;j<n;++j){
        if(era[j].second.first<=query&&era[j].second.second>=query){
          cout << era[j].first << " " << query-era[j].second.first+1 << endl;
          break;
        }

        if(j==q-1) cout << "Unknown" << endl;
      }
    }
  }

  return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int N,Q;
typedef pair<unsigned int,pair<unsigned int,string> > P;
vector<P> que;
int main(){
	while(cin>>N>>Q,N||Q){
		que.clear();
		unsigned int A[1010]={0};
		for(int i = 0;i < 1010;i++){
			A[i] = 0;
		}

		for(int i = 0;i < N;i++){
			string str;
			unsigned int eray,wesy;
			cin>>str>>eray>>wesy;
			que.push_back(P(wesy,mp(eray,str)));
			A[i] = wesy;
		}
		sort(que.begin(),que.end());
		sort(A,A+N);
		for(int i = 0;i<Q;i++){
			unsigned wes;
			cin>>wes;
			int k = lower_bound(A,A+N,wes)-A;
			//cout<<que[k].first-wes<<endl;
			if(que[k].second.first>que[k].first-wes){
				cout <<que[k].second.second<<" "<<que[k].second.first-(que[k].first-wes)<<endl;
			}else{
				cout <<"Unknown"<<endl;
			}
		}
		rep(i,N){
			cout <<que[i].first<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
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<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
using namespace std;
const int maxn=100010;
const double pi=acos(-1);
const double eps=1e-9;
struct dd{
    string s;
    int l,b,e;
}a[1010];
bool cmp(dd x,dd y)
{
    return x.e<y.e;
}
int main()
{
    int n,m,i,j,k,t;
    while (~scanf("%d%d",&n,&m),n||m)
    {
        for (i=0;i<n;i++) {cin>>a[i].s>>a[i].l>>a[i].e;a[i].b=a[i].e-a[i].l+1;}
        sort(a,a+n,cmp);

        for (i=0;i<m;i++)
        {
            cin>>t;
            cout<<t<<endl;
            if (t<a[0].b||t>a[n-1].e) {printf("Unknown\n");continue;}
            for (j=0;j<n;j++)
            {
                if (a[j].b>t) break;
            }
            if (t>a[j-1].e) printf("Unknown\n");
            else cout<<a[j-1].s<<' '<<t-a[j-1].b+1<<endl;

        }
    }
    return 0;
}

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

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

using namespace std;
typedef long long ll;

int main()
{
    int n,m;
    while(cin >> n >> m) {
        if(n == 0 && m == 0) break;
        
        map<string,pair<int,int> > ma;
        
        rep(i,n) {
            string s;
            int a,b;
            cin >> s >> a >> b;
            
            ma[s] = make_pair(b-a+1,b);
        }

        rep(i,m) {
            int x;
            cin >> x;
        
            bool flag = true;
            map<string,pair<int,int> >::iterator ite;
            for(ite = ma.begin();ite != ma.end();ite++) {
                int s = ite->second.first;
                int e = ite->second.second;

                if(s <= x && x <= e) {
                    cout << ite->first << " " << x - s + 1 << endl;
                    flag = false;
                    break;
                }
            }

            if(flag) cout << "Unkown" << endl;
        }
    }

    return 0;
}