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-data_.a) > (b-a);
    }
    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 <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef pair<int, pii> pip;
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
 

int main(){
	int n, m;
	string s;
	int a, b;
	while(cin>>n>>m && n > 0 && m > 0){
		map<int,string> ms, me;
		rep(i, n){
			cin>>s>>a>>b;
			ms[b - a + 1] = s;
			me[b] = s;
		}
		rep(i, m){
			cin>>a;
			auto its = ms.upper_bound(a);
			auto ite = me.upper_bound(a);


			if(its == ms.begin() || ite == me.end()){
				cout<<"Unknown"<<endl;
				continue;
			}
			--its;
			--ite;


			//cout<<its->fi<<" "<<ite->fi<<" "<<a<<endl;

			if(its->fi <= a && a <= ite->fi){
				cout<<its->se<<" "<<a - its->fi + 1<<endl;
			}
			else cout<<"Unknown"<<endl;
		}
	}
}