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;
#define rep(i,n) for(int i=0;i<(n);i++)

int N,Q;

struct Data {
    int a,b;
    string ss;
    Data() {};
    Data(int a,int b,string ss) :
        a(a),b(b),ss(ss) {};

    bool operator<(const Data& data_) const {
        return (data_.b) > (b);
    }
    bool operator<(const int& val) const {
        return val > b;
    }
};

void solve() {
    Data data[1003];

    rep(i,N) {
        int a,b;
        string ss;
        cin>>ss>>a>>b;

        data[i] = Data(a,b,ss);
    }
    sort(data,data+N);

    rep(i,Q) {
        int a;
        cin>>a;
        int pos = lower_bound(data,data+N, a) - data;
        if(pos ==N) {
            cout<<"Unknown"<<endl;
            continue;
        }
        int t = a - (data[pos].b-data[pos].a);
        if(t <= 0) {
            cout<<"Unknown"<<endl;
            continue;
        }
        cout<<data[pos].ss<<" "<<t<<endl;


        
        
    }


}

int main() {
    while(cin>>N>>Q) {
        if(N+Q==0) return 0;
        solve();
    }

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

struct Era{
    string name;
    int s, t;
};

signed main(){
    int n, q;
    while(1){
        cin >> n >> q;
        if(n + q == 0) break;
        vector<Era> d(n);
        rep(i, 0, n){
            string s;
            int a, b;
            cin >> s >> a >> b;
            d[i].name = s;
            d[i].s = b - a + 1;
            d[i].t = b;
        }
        rep(j, 0, q){
            int y;
            cin >> y;
            string era = "";
            int ans = -1;
            rep(i, 0 ,n){
                if(d[i].s <= y && y <= d[i].t){
                    era = d[i].name;
                    ans = y - d[i].s + 1;
                    break;
                }
            }
            if(ans == -1){
                cout << "Unknown" << endl;
            }else{
                cout << era << " " << ans << endl;
            }
        }
    }
}

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

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

using namespace std;

struct D{
    bool operator<(const D& rhs) {
        return e < rhs.e;
    }
    int s, e;
    string name;
};

int main(void){
    while (1) {
        int n, q;
        cin >> n >> q;
        if (!n && !q) break;
        
        vector<D> data(n);
        for (int i = 0; i < n; i++) {
            int a,b;
            cin >> data[i].name >> a >> b;
            data[i].s = b-a+1;
            data[i].e = b;
        }
        sort(data.begin(), data.end());
        
        for (int i = 0; i < q; i++) {
            int x;
            cin >> x;
            
            for (int j = 0; j < n; j++) {
                if (data[j].s <= x && data[j].e >= x) {
                    cout << data[j].name << " " << x - data[j].s + 1 << endl;
                    j = n;
                    break;
                }
                if (j == n-1) cout << "Unknown" << endl;
            }
        }
    }
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
  
using namespace std;

int main()
{
	int n, q;
	while(1){
		cin >> n >> q;
		if(n == 0 && q == 0) break;
		map<string, pair<long long int, long long int> > era;
		string inputs[1000];
		long long int by, wy;
		for(int i = 0; i < n; i++){
			cin >> inputs[i] >> by >> wy;
			era[inputs[i]] = make_pair<long long int, long long int>(wy - (by - 1), wy);
		}
		long long int query;
		for(int i = 0; i < q; i++){
			cin >> query;
			for(int j = 0; j < n; j++){
				if(era[inputs[j]].first <= query && era[inputs[j]].second >= query){
					cout << inputs[j] << " " << query - era[inputs[j]].first + 1 << endl;
					break;
				} else if(j == n - 1){
					cout << "Unknown" << endl;
				}
			}
		}
	}
	return 0;
}

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

#define f first
#define s second

typedef pair<int, int> P;
typedef pair<P, string> P2;

int main(){
  int n, m;
  
  while(cin >> n >> m){
    if(n == 0 && m == 0) break;
    P2 era[1010];
    int tmp;
    for(int i = 0 ; i < n ; i++){
      cin >> era[i].s >> tmp >> era[i].f.s;
      era[i].f.f = era[i].f.s - tmp;
    }
    
    sort(era, era+n);
     
    while(m--){
      bool flag = false;
      cin >> tmp;
      for(int i = 0 ; i < n ; i++){
	if(era[i].f.f < tmp && tmp <= era[i].f.s){
	  cout << era[i].s << ' ' << tmp-era[i].f.f << endl;
	  flag = true;
	  break;
	}
      }
      if(!flag) cout << "Unknown" << endl;
    }
  }
  return 0;
}