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>
using namespace std;
typedef struct calendar {
    int wy, eby;
    string name;
    bool operator<(const calendar &another) const {
	return wy < another.wy;
    };
}CAL;
int main() {
    int n, q;
    while (cin >> n >> q && n&&q) {
	CAL data[1000];
	for (int i = 0; i<n; ++i) 
            cin >> data[i].name >> data[i].eby >> data[i].wy;
	sort(data, data+n);
	for (int i = 0; i<q; ++i) {
	    int j, y; cin >> y;
	    for (j = 0; j<n; ++j)
		if (data[j].wy >= y) break;
	    if (j == n) cout << "Unknown" << endl;
	    else if (data[j].wy - data[j].eby + 1 <= y) cout << data[j].name << " " << y-(data[j].wy-data[j].eby) << endl;
	    else cout << "Unknown" << endl;
	}
    }
    return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<ll, ll> P;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, Q;
  while(cin>>N>>Q,N||Q) {
    map<P, string> MAP;
    FOR(i,0,N) {
      string s;
      ll a, b;
      cin >> s >> a >> b;
      MAP[P(a, b)] = s;
    }
    FOR(i,0,Q) {
      ll in; cin >> in;
      bool ok = false;
      for(auto m : MAP) {
        ll end = m.first.second;
        ll start = end - m.first.first + 1;
        if(in >= start && in <= end) {
          cout << m.second << " " << in - start + 1 << endl;
          ok = true;
          break;
        }
      }
      if(!ok) {
        puts("Unknown");
      }
    }
  }
  return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    while(true){
        int N, Q; cin >> N >> Q;
        if(N == 0) break;
        vector<string> era_name;
        vector<int> st;
        vector<int> fin;
        rep(i, N){
            string S; int jy, wy;
            cin >> S >> jy >> wy;
            era_name.push_back(S);
            st.push_back(wy-jy+1);
            fin.push_back(wy);
        }
        rep(i, Q){
            int idx = -1;
            int year; cin >> year;
            rep(j, N){
                if(st[j] <= year && year <= fin[j]){
                    idx = j;
                    break;
                }
            }
            if(idx == -1){
                cout << "Unknown" << endl;
            }
            else{
                cout << era_name[idx] << " " << year - st[idx] + 1 << endl;
            }
        }
    }
    return 0;
}

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

using namespace std;
    
#define NMAX 1000

struct S{
	int e,w;
	string n;
};

int main(void){
       
   int N,Q;
   int q;
   S year[NMAX];

   while(1){
	   cin>>N>>Q;
	   if(N==0&&Q==0) break;
	   for(int i=0;i<N;i++){
		   cin>>year[i].n>>year[i].e>>year[i].w;
	   }
	   for(int i=0;i<Q;i++){
		   cin>>q;
		   for(int i=0;i<N;i++){
			   if(q>=year[i].w-year[i].e+1&&q<=year[i].w){
				   cout<<year[i].n<<" "<<q-(year[i].w-year[i].e)<<endl;
				   break;
			   }
			   if(i==N-1) cout<<"Unknown"<<endl;
		   }
	   }
   }

   return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n,q;
    cin >> n >> q;
    if(n==0) return 0;
    map<int,pair<int,string>> mp;
    int sei,wa;
    string s;
    for(int i=0;i<n;i++){
      cin >> s >> wa >> sei;
      mp[sei-wa+1]={0,s};
      if(mp.find(sei+1)==mp.end()) mp[sei+1]={1,s};
    }
    for(int i=0;i<q;i++){
      cin >> sei;
      auto itr=mp.upper_bound(sei);
      if(itr==mp.begin()){
        cout << "Unknown" << endl;
      }else{
        itr--;
        if(itr->second.first){
          cout << "Unknown" << endl;
        }else{
          cout << itr->second.second SP sei-itr->first+1 << endl;
        }
      }
    }
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>

using namespace std;
const int maxn = 1000000000;
struct node
{
    int wy;
    int by;
    char name[20];
}e[1005];

int main()
{
    int n = 0, q = 0;
    int num = 0;
    while (scanf("%d%d", &n, &q) == 2)
    {
        if (n == 0 & q == 0) break;
        for (int i=0; i<n; i++) scanf("%s%d%d", e[i].name, &e[i].by, &e[i].wy);
        while (q--)
        {
            scanf("%d", &num);
            int min = maxn, ans = 0, count = 0;
            for (int i=0; i<n; i++)
            {
                ans = e[i].wy-num;
                if (ans >= 0 && ans <= min)
                {
                    min = ans;
                    count = i;
                }
            }
            ans = e[count].by-min;
            if (ans>0) printf("%s %d\n", e[count].name, ans);
            else printf("Unknown\n");
        }
    }
    return 0;
}