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 <string>


using namespace std;

int main(){

	int n,q;

	while(cin>>n>>q){
		if(n==0 && q==0)break;
		string *str;
		int *eraY,*wesY;

		str = new string [n];
		eraY = new int [n];
		wesY = new int [n];

		for(int i=0;i<n;i++){
			cin>>str[i]>>eraY[i]>>wesY[i];
		}


		for(int i=0;i<q;i++){

			int query;
			cin>>query;

			int flag=0;
			for(int j=0;j<n;j++){
				if(query<=wesY[j] && query> wesY[j]-eraY[j]){
					cout<<str[j]<<" "<<eraY[j]-(wesY[j]-query)<<endl;
					flag=1;
					break;
				}
			}

			if(flag==0){
				cout<<"Unknown"<<endl;
			}

		}

	}

	return 0;
}

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

using namespace std;

struct plot {
    string era;
    int y_era;
    int y_westan;
};

int main(){
    int n, q;
    while (cin >> n >> q && n | q)
    {
        vector<plot> input(n);
        for (int i = 0; i < n; i++)
        {
            string era;
            int y_era, y_west;
            cin >> era >> y_era >> y_west;
            input[i] = { era, y_era, y_west };
        }
        sort(input.begin(), input.end(), [](const plot& a, const plot& b){
            return a.y_westan < b.y_westan;
        });
        for (int i = 0; i < q; i++)
        {
            int y; cin >> y;
            int j = 0;
            while (j < n && y > input[j].y_westan) j++;
            // cout << j << endl;
            if (j < n && y - input[j].y_westan + input[j].y_era > 0){
                cout << input[j].era << " " << y - input[j].y_westan + input[j].y_era << endl;
            }
            else{
                cout << "Unknown" << endl;
            }
        }
    }
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999
#define eps 1e-9

int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        
        string s[1100];
        int a[1100],b[1100];
        rep(i,n){
            cin>>s[i]>>a[i]>>b[i];
        }
        rep(i,m){
            int x;
            cin>>x;
            bool f=true;
            rep(i,n){
                if(x<=b[i] && (b[i]-a[i])<x){
                    cout<<s[i]<<" "<<x-(b[i]-a[i])<<endl;
                    f=false;
                    break;
                }
            }
            if(f)cout<<"Unknown"<<endl;
        }
    }
}

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

struct era{
  string name;
  int fr, to;
  bool operator<(const era &x)const{
    if(fr < x.fr) return true;
    return false;
  }
  era(string name, int fr, int to) : name(name), fr(fr), to(to) {}
};

int main(){
  int n, q;
  while(cin >> n >> q and n + q){
    vector<era> eras;
    REP(i, n){
      string name; int eby, wy;
      cin >> name >> eby >> wy;
      eras.emplace_back(name, wy-eby+1, wy);
    }
    sort(ALL(eras));
    REP(i, q){
      int query; cin >> query;
      int target = -1;
      REP(j, eras.size()-1) if(eras[j+1].fr > query){ target = j; break; }
      if(target == -1){
        if(eras[eras.size()-1].to < query or query < eras[eras.size()-1].fr) cout << "Unknown" << endl;
        else cout << eras[eras.size()-1].name << " " << query - eras[eras.size()-1].fr + 1 << endl;
        continue;
      }
      if(eras[target].to < query or query < eras[target].fr) cout << "Unknown" << endl;
      else cout << eras[target].name << " " << query - eras[target].fr + 1 << endl;
    }
  }
  return 0;
}

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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;
typedef pair<int,int> pii;

int main () {
    int N, Q;
    while (cin >> N >> Q, N + Q) {
        vector<string> name(N);
        vector<pii> len(N);
        REP (i, 0, N) {
            cin >> name[i];
            int f, e;
            cin >> f >> e;
            len[i].first = e - f + 1;
            len[i].second = e;
        }
        REP (i, 0, Q) {
            int q;
            cin >> q;
            int cnt = 0;
            string ans = "";
            int l = 0;
            REP (j, 0, N) {
                if (len[j].first <= q && q <= len[j].second) {
                    cnt++;
                    ans = name[j];
                    l = q - len[j].first + 1;
                }
            }
            if (cnt >= 1) {
                cout << ans << " " << l << endl;
            } else {
                cout << "UnKnown" << endl;
            }

        }
    }
    return 0;
}

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

int main() {

  while( true ) {

    long long int n, q;
    cin >> n >> q;
    if ( n == 0 ) break;

    vector< pair< string, pair< long long int, long long int > > > v;

    for ( long long int i = 0; i < n; i++ ) {

      string s;
      long long int e, w;
      cin >> s >> e >> w;
      v.push_back( make_pair( s, make_pair( e, w ) ) );

    }

    for ( long long int i = 0; i < q; i++ ) {

      long long int in;
      cin >> in;

      bool f = true;
      for ( long long int j = 0; j < n; j++ ) {
	if ( in > v[j].second.second - v[j].second.first && in <= v[j].second.second ) {
	  cout << v[j].first << " " << v[j].second.first - ( v[j].second.second - in ) << endl;
	}
      }
      if ( f == true ) {
	cout << "Unknown" << endl;
      }

    }

  }

  return 0;

}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[1000],b[1000],m,n,p;
  char s[1000][17];
  while(cin>>n>>m&&n&&m){
    for(i=0;i<n;i++)
      cin>>s[i]>>a[i]>>b[i];
    for(i=0;i<m;i++){
      cin>>p;
      for(j=0;j<m;j++){
	if(b[j]-a[j]<p&&p<=b[j])
	  break;
      }
      if(j==m)
	cout<<"Unknown"<<endl;
      else
	cout<<s[j]<<" "<<a[j]-b[j]+p<<endl;
    }
  }
  return 0;
}