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 <vector>
#include <string>
using namespace std;
struct po{
  string str;
  int era,end;
};

int main() {
  while(1){
    int n,m;
    cin >> n >> m;
    if(n==0 && m == 0) break;
    
    po ls[1001];
    for(int i=0;i<n;i++){
      cin >> ls[i].str >>  ls[i].end >> ls[i].era;
      ls[i].era -= (ls[i].end-1);
    }
    for(int i=0;i<m;i++) {
      int a,flg = 0;
      cin >> a;
      for(int i=0;i<n-1;i++) 
	if(ls[i].era<=a && a <ls[i+1].era) {
	  if(ls[i].end >= a-ls[i].era+1)cout << ls[i].str <<" "<<a-ls[i].era+1<<endl,flg=1;
	  break;
	}
      if(flg == 0 && ls[n-1].era <= a && ls[n-1].end<=a-ls[n-1].era+1) 
	 cout << ls[n-1].str << " "<< a-ls[n-1].era+1 <<endl,flg = 1;
      if(flg == 0) 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{
                        int lb=0,rb=n;
                        while(rb-lb>1){
                              int mid=(lb+rb)/2;
                              if(V[mid].first>a){
                                    rb=mid;
                              }else{
                                    lb=mid;
                              }
                        }
                        if(a-V[lb].first==0){
                              cout<<"Unknown"<<endl;
                        }else{
                              cout<<s[V[lb].second]<<" "<<a-V[lb].first<<endl;
                        }
                  }
            }
      }
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n, q;
	while (scanf("%d%d", &n, &q), n) {
		map<int, string>mp;
		rep(i, n) {
			string s;
			int j, k;
			cin >> s >> j >> k;
			mp[k - j] = s;
		}
		rep(i, q) {
			int d; scanf("%d", &d);
			auto it = mp.lower_bound(d);
			it--;
			if (it == --mp.begin()) {
				puts("Unknown");
				continue;
			}
			if ((*it).first == d) {
				puts("Unknown");
				continue;
			}
			if (it != --mp.end()) {
				if ((*++it).first == d) {
					puts("Unknown");
					continue;
				}
				else it--;
			}
			cout << (*it).second << ' ' << d - (*it).first << endl;
		}
	}
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, q;
  while (cin >> n >> q, n) {
    vector<string> s(n);
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
      cin >> s[i] >> a[i] >> b[i];
    }
    while (q--) {
      int x;
      cin >> x;
      [&] {
        for (int i = 0; i < n; ++i) {
          if (b[i] - a[i] < x and x <= b[i]) {
            cout << s[i] << ' ' << x + a[i] - b[i] << '\n'; 
            return;
          }
        }
        cout << "Unknown\n";
      }();
    }
  }
}

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

using namespace std;

int main()
{
    int N, Q;

    while (cin >> N >> Q, N || Q) {
        vector<pair<int, string> > memo;

        for (int i = 0; i < N; i++) {
            string s;
            int ey, wy;

            cin >> s >> ey >> wy;
            memo.push_back(make_pair(wy - ey, s));
        }
        sort(memo.begin(), memo.end());

        cerr << N << " " << Q << endl;
        for (int i = 0; i < Q; i++) {
            int q;

            cin >> q;
            bool flag = false;
            vector<pair<int, string> >::iterator it = memo.begin();

            while (it != memo.end()) {
                if ((*it).first > q && memo.size() > 1) {
                    advance(it, -1);
                    flag = true;
                    cout << (*it).second << " " << q - (*it).first << endl;
                    break;
                }

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

    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cassert>
#include <sstream>
#include <bitset>
#include <numeric>
#include <climits>
#include <string>
#include <cctype>
#include <ctime>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <set>

#define mm(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define pb push_back

using namespace std;

const int maxn = 111;
const int maxm = 111;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;

int n, m;

void solve(){}

struct Y{
    int base, tim;
    char name[100];

    void load(){
        scanf("%s%d%d", name, &base, &tim);
    }

    int at(int x){
        if (x > tim) return -1;
        if (x <= tim - base) return -1;
        return x - (tim - base);
    }
}year[1111];

int main(){
    while (1){
        scanf("%d%d", &n, &m);
        if(n == 0 && m == 0) return 0;
        for (int i = 1; i <= n; ++i){
            year[i].load();
        }
        for (int i = 1; i <= m; ++i){
            int a;
            scanf("%d", &a);
            bool flag = 0;
            int t;
            for (int j = 1; j <= n; ++j)
                if ((t = year[j].at(a)) != -1){
                    printf("%s %d\n", year[j].name, t);
                    flag = 1;
                    break;
                }
            if (!flag)
                printf("Unknown\n");
        }
    }
}