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

struct Date
{
    char name[20];
    int begin,end;
	int d;
};
Date date[1003];

bool cmp(Date a, Date b)
{
    return a.begin < b.begin;
}

bool find(int n, int x, int &k, int &y)
{
    int mid,bot = 0, top = n - 1,flag = 0;

    if (x < date[0].begin)
        return false;
	if (x > date[n - 1].end)
		return false;

    while (bot <= top && !flag)
    {
        mid = (bot + top) / 2;
        if (date[mid].begin == x)
        {
            k = mid;
            y = 1;
            flag = 1;
        }
        else if (date[mid].begin < x)
            bot = mid + 1;
        else
            top = mid - 1;
    }

    k = top;
    y = x - date[top].begin + 1;
	if (y > date[top].d)
			return false;
    return true;
}

int main()
{
    int n,q,d,x,y,i,k;
    while (scanf("%d%d",&n,&q) != EOF)
    {
        if (n == 0 && q == 0)
            break;
        for (i = 0; i < n; i++)
        {
            scanf("%s %d %d",date[i].name, &date[i].d, &date[i].end);
			getchar();
            date[i].begin = date[i].end - date[i].d + 1;
        }
        sort(date, date + n, cmp);

        for (i  = 0; i < q; i++)
        {
			cin >> x;
            if (find(n, x, k, y))
            {
                cout << date[k].name << " " << y << endl;
            }
            else
                cout << "Unknown" << endl;
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
      int n,q,a,b;
      while(cin>>n>>q&&(n||q)){
            int mi=INF;
            string s[1000];
            vector<P>V;
            REP(i,n){
                  cin>>s[i]>>a>>b;
                  b-=a;
                  mi=min(mi,b);
                  V.PB(MP(b,i));
            }
            sort(ALL(V));
            while(q--){
                  cin>>a;
                  if(a<=mi){
                        cout<<"Unknown"<<endl;
                  }else{
                        for(int i=0;i<V.size()-1;i++){
                              if(V[i].first<=a&&a<V[i+1].first){
                                    if(a-V[i].first==0){
                                          cout<<"Unknown"<<endl;
                                    }else{
                                          cout<<s[V[i].second]<<" "<<a-V[i].first<<endl;
                                    }
                              }
                        }
                        if(V[V.size()-1].first<=a){
                              if(a-V[V.size()-1].first==0){
                                    cout<<"Unknown"<<endl;
                              }else{
                                    cout<<s[V[V.size()-1].second]<<" "<<a-V[V.size()-1].first<<endl;
                              }
                        }
                  }
            }
      }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

struct query {
  string name;
  int length;
  int year;
};

main()
{
  int N, Q;
  query q[1001];
  
  while( cin >> N >> Q, !(N == 0 && Q == 0) ) {
   
    Rep(i, N) {
      string s;
      int l, y;
      cin >> s >> l >> y;
      q[i] = (query){ s, l, y };
    }

    Rep(i, Q) {
      int y;
      cin >> y;

      bool flag = false;
      Rep(i, N) {
	if( q[i].year - q[i].length < y && y - (q[i].year - q[i].length) <= q[i].length ) {
	  cout << q[i].name << " " << y - (q[i].year - q[i].length) << endl;
	  flag = true;
	  break;
	}
      }

      if( !flag ) cout << "Unknown" << endl;
      
    }
    
  }
  
}

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

using namespace std;

int main(){
	int N, Q;
	while(cin >> N >> Q, N){
		vector< pair<string, pair<int, int> > > vp;
		string str; int Y, W; 
		for(int i=0;i<N;i++){
			cin >> str >> Y >> W;
			vp.push_back(make_pair(str, make_pair(W-Y, Y)));
		}
		for(int i=0;i<Q;i++){
			string ans = "Unknown";
			cin >> W;
			for(int j=0;j<N;j++){
				if(0 < W-vp[j].second.first && W-vp[j].second.first <= vp[j].second.second){
					ans = vp[j].first;
					Y = W-vp[j].second.first;
				}
			}
			if(ans != "Unknown") cout << ans << " " << Y << endl; 
			else                 cout << ans << endl;
		}
	}
}

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

int main()
{
  int n,q;
  for(;cin>>n>>q,n;)
    {
      string name[n];
      int byear[n];
      int wyear[n];
      for(int i=0;i<n;i++)
	  cin>>name[i]>>byear[i]>>wyear[i];
      
      for(int i=0;i<q;i++)
	{
	  bool flag=true;
	  int qe;
	  cin>>qe;
	  for(int x=0;x<n;x++)
	    {
	      if(qe<=wyear[x] &&qe>wyear[x]-byear[x])
		{
		  cout<<name[x]<<" "<<qe-(wyear[x]-byear[x])<<endl;
		  flag=false;
		  break;
		}
	    }
	  if(flag)
	    cout<<"Unknown"<<endl;
	}
      

    }

}

C++: #include "iostream"
#include "string"
using namespace std;
int main(void)
{
	int n,q;
	while (cin>>n>>q,n) {
		pair<string,pair<int,int> > p[n];
		for (int i = 0; i < n; i++) {
			cin>>p[i].first>>p[i].second.first>>p[i].second.second;
		}
		int query;
		for (int i = 0; i < q; i++) {
			bool f=false;
			cin>>query;
			for (int j = 0; j < n; j++) {
				if(p[j].second.second-p[j].second.first+1<=query&&query<=p[j].second.second)
				{
					cout<<p[j].first<<" "<<p[j].second.first-(p[j].second.second-query)<<endl;
					f=true;
				}
			}
			if(!f) cout<<"Unknown"<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
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[1005];
    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;
	}
	if(i==n-1)
	    cout << "Unknown" << endl;
      }
    }
  }
  return 0;
}