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

class era
{
	public:

		string name;
		int base,west;

		era(string n, int b, int w)
		{
			name = n;
			base = b;
			west = w;
		}

		bool operator<(const era& e) const
		{
			return (west < e.west);
		}
};

int main()
{
	int Q,N,n,b,w;
	string nm;
	ifstream fin("A.txt");

	while(fin >> Q >> N, Q||N)
	{
		vector<era> data;
		while(Q--)
		{
			fin >> nm >> b >> w;
			data.push_back(era(nm,b,w));
		}
		sort(data.begin(), data.end());

		while(N--)
		{
			fin >> n;
			string anss;
			int ansn;
			bool ok=false;
			for(int i=0; i<data.size(); i++)
			{
				if(n-data[i].west+data[i].base>0 && n-data[i].west<=0)
				{
					ansn = n-data[i].west+data[i].base;
					anss = data[i].name;
					ok = true;
					break;
				}
			}

			if(ok)
			{
				cout << anss << " " << ansn << endl;
			}
			else
			{
				cout << "Unknown" << endl;
			}
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q,year;
  int y[1000],b[1000];
  string s,era[1000];
  while(1){
    cin>>n>>q;
    if(n==0 && q==0) break;
    for(int i=0;i<n;i++){
      cin>>era[i]>>b[i]>>y[i];
    }
    for(int i=0;i<q;i++){
      cin>>year;
      for(int j=0;j<n;j++){
	if(year<=y[j] && year>y[j]-b[j]){
	  cout<<era[j]<<" "<<year-y[j]+b[j]<<endl;
	  break;
	}
	else if(j==n-1) cout<<"Unknown"<<endl;
      }
    }
  }
  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2242>
 問題文============================================================
 
 =================================================================
 解説=============================================================
 ================================================================
 */
int N,Q;
struct Era{
    string name;
    int from,to;
    Era(string era = "",int from = 0,int to = 0):name(era),from(from),to(to){};
    bool operator <(const Era& o) const{ return from < o.from; }
};
void solve(){
    vector<Era> Eras(N);
    for(int i = 0; i < N;i++){
        string name;int x,y; cin >> name >> x >> y;
        Eras[i] = Era(name,y-x+1,y);
    }
    sort(Eras.begin(),Eras.end());
    while(Q--){
        int year; cin >> year;
        [&]{
            for(int i = 0; i < N;i++){
                if(Eras[i].from <= year && year <= Eras[i].to){
                    cout << Eras[i].name << " " << year - Eras[i].from + 1 << endl;
                    return;
                }
            }
            cout << "Unknown" << endl;
        }();
    }
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> N >> Q,N){
        solve();
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++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>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    for (;;) {
        int N, Q; cin >> N >> Q;
        if (N == 0) break;
        vector<string> eraName(N);
        vi eraBasedYear(N), westernYear(N);
        REP(i, N) {
            cin >> eraName[i] >> eraBasedYear[i] >> westernYear[i];
        }
        while (Q--) {
            int query; cin >> query;
            string name;
            int year;
            REP(i, N) {
                if (query <= westernYear[i] and westernYear[i] - eraBasedYear[i] < query) {
                    name = eraName[i];
                    year = query - westernYear[i] + eraBasedYear[i];
                }
            }
            if (name.size()) {
                cout << name << " " << year << endl;
            } else {
                cout << "Unknown" << endl;
            }
        }
   }

    return 0;
}

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

class calender{
public:
  string s;
  int ey,wy;
  bool operator<(const calender &a)const{
    return wy < a.wy;
  }
};
int main(){
  int n,q;
  while(cin>>n>>q,n){
    calender c[1000];
    for(int i=0;i<n;i++)cin>>c[i].s>>c[i].ey>>c[i].wy;
    sort(c,c+n);
    for(int i=0;i<q;i++){
      int query;
      cin>>query;
      for(int i=0;i<n;i++){
	if(query <= c[i].wy){
	  if(c[i].wy - query < c[i].ey){
	    cout << c[i].s << " " << c[i].ey - (c[i].wy - query)<< endl;
	  }else{
	    cout << "Unknown" << endl;
	  }
	  break;
	}
      }
    }
  }
  return 0;
}