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++: //Era Name
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef struct ERA{
  string name;
  ll l, f;
}era;

era mk(string s, ll l, ll f){
  era ret;
  ret.name=s;
  ret.l=l;
  ret.f=f;
  return ret;
}

int main(){
  ll N, Q;
  while(cin>>N>>Q, !(N==0&&Q==0)){
    vector<era> v;
    for(ll i=0; i<N; i++){
      string s;
      ll l, f;
      cin>>s>>l>>f;
      v.push_back(mk(s, l, f));
    }
    for(ll i=0; i<Q; i++){
      ll q;
      cin>>q;
      bool flag=false;
      for(int j=0; j<v.size(); j++){
	if((v[j].f-v[j].l)<q && q<=v[j].f){
	  cout<<v[j].name<<" "<<v[j].l-(v[j].f-q)<<endl;
	  flag=true;
	break;
	}
      }
      if(!flag)cout<<"Unknown"<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;
typedef pair<i_i, string> era;


int main()
{
    int n, m;
    while(cin >> n >> m, n) {
        vector<era> data;
        rep(i, n) {
            era tmp;
            cin >> tmp.second >> tmp.first.second >> tmp.first.first;
            data.pb(tmp);
            if (tmp.first.second != 1) {
                tmp.first.first -= tmp.first.second - 1;
                tmp.first.second = 1;
                data.pb(tmp);
            }
        }
        sort(data.begin(), data.end());
        int pt = 1;
        for (int i = 1; i < data.size(); i++) {
            if (data[i-1] != data[i]) {
                data[pt++] = data[i];
            } else {
                data[pt] = data[i];
            }
        }
        rep(i, m) {
            int tmp;
            bool fl = false;
            cin >> tmp;
            for (int j = 1; j < pt; j++) {
                if (data[j-1].first.first <= tmp && 
                        tmp <= data[j].first.first) {  
                    if (data[j-1].second == data[j].second) {
                        cout << data[j].second << " ";
                        cout << data[j-1].first.second + tmp 
                            - data[j-1].first.first << endl;
                    } else {
                        cout << "Unknown" << endl;
                    }
                    fl = true;
                    break;
                }
            }
            if (!fl) {
                cout << "Unknown" << endl;
            }
        }
    }
    return 0;
}

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

string s[1010];
int main() {
	while(true) {
		int n, m;
		cin >> n >> m;
		if(!n && !m) break;
		pair<int, int> ma[1010];
		for(int i=0; i<n; ++i) {
			cin >> s[i];
			int a, b;
			cin >> a >> b;
			ma[i] = {b-a+1, b};
		}
		for(int i=0; i<m; ++i) {
			int a;
			cin >> a;
			bool flag = true;
			for(int j=0; j<n; ++j) {
				if(ma[j].first <= a && a <= ma[j].second) {
					flag = false;
					cout << s[j] << " " << a-ma[j].first+1 << endl;
					break;
				}
			}
			if(flag) {
				cout << "Unknown" << endl;
			}
		}
	}
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<ll, ll> P;
int main()
{
  int N, Q;
  while(cin>>N>>Q,N||Q) {
    map<P, string> MAP;
    FOR(i,0,N) {
      string s;
      ll a, b;
      cin >> s >> a >> b;
      MAP[P(a, b)] = s;
    }
    FOR(i,0,Q) {
      ll in; cin >> in;
      bool ok = false;
      for(auto m : MAP) {
        ll end = m.first.second;
        ll start = end - m.first.first + 1;
        if(in >= start && in <= end) {
          ok = true;
          cout << m.second << " " << in - start + 1 << endl;
        }
      }
      if(!ok) {
        puts("Unknown");
      }
    }
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cassert>
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <iterator>
#include <queue>
#include <utility>

using namespace std;

int N, Q;
struct P {
    int begin, end; // [begin, end]
    P(int begin = 0, int end = 0) : begin(begin), end(end) {}
    bool contains(int year) {
        return begin <= year && year <= end;
    }
    int transform(int year) {
        return year - begin + 1;
    }
};
map<string, P> Map;
vector<int> Queries;
bool input() {
    cin >> N >> Q;
    if (N == 0 && Q == 0) return false;
    Map.clear();
    Queries.clear();
    for (int i = 0; i < N; i++) {
        string Name; int Year, GYear;
        cin >> Name >> Year >> GYear;
        Map[Name].begin = GYear - Year + 1;
        Map[Name].end   = max(Map[Name].end, GYear);
    }
    for (int i = 0; i < Q; i++) {
        int Y;
        cin >> Y;
        Queries.push_back(Y); 
    }
    return true;
}

void solve() {
    for (int i = 0; i < Q; i++) {
        for (map<string, P>::iterator it = Map.begin(); it != Map.end(); it++) {
            if (it->second.contains(Queries[i])) {
                cout << it->first << " " << it->second.transform(Queries[i]) << endl;
                goto next;
            }
        }
        cout << "Unknown" << endl;
next:;
    }
}

int main() {
    while (input()) {
        solve();
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string S[100000],U;int n,a,b,c,d,p[100000][2];
int main(){
	while(true){
		cin>>a>>b;if(a==0 && b==0){break;}
		for(int i=0;i<a;i++){
			n=0;cin>>U>>c>>d;
			S[i]=U;
			p[i][0]=d-c+1;
			p[i][1]=d;
		}
		for(int i=0;i<b;i++){
			cin>>c;
			for(int j=0;j<a;j++){
				if(c>=p[j][0] && c<=p[j][1]){
					cout<<S[j]<<' '<<c-p[j][0]+1<<endl;
					goto E;
				}
			}
			cout<<"Unknown"<<endl;
			E:;
		}
	}
}