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 <map>
#include <string>
#include <algorithm>
using namespace std;
 
typedef pair<int,int> P;
 
int main(){
    int N, Q;

    while( cin >> N >> Q, N || Q ){
        // m[name] := テ・ツ陳古ヲツ堋ヲnameテ」ツ?ォテ・ツッツセテ・ツソツ愿」ツ?凖」ツつ?テ・ツ陳古ヲツ堋ヲ,ティツ・ツソテヲツ堋ヲテ」ツ?ョテヲツ慊?・ツ、ツァ)テ」ツ?ョテァツオツ?」ツつ津ィツソツ氾」ツ??
        map<string, P> m;
        // v := テ・ツ陳古ヲツ堋ヲテ」ツ?ョテ・ツ青催・ツ可催」ツつ津、ツソツ敕ヲツ個?
        vector<string> v;
         
        for(int i = 0 ; i < N ; i++ ){
            // name := テ・ツ陳古ヲツ堋ヲテ」ツ?ョテ・ツ青催・ツ可? y1 := テ・ツ陳古ヲツ堋ヲ, y2 := ティツ・ツソテヲツ堋ヲ
            string name;
            int y1, y2;
             
            cin >> name >> y1 >> y2;
            if( m.count(name) ){
                if( m[name].second < y2 ){
                    m[name] = P(y1, y2);
                }
            }else{
                m[name] = P(y1, y2);
                v.push_back( name );
            }
        }
         
        for(int i = 0 ; i < Q ; i++ ){
            int q;
            cin >> q;
            
            // flag := ティツァツ」テ」ツ?古・ツュツ佚・ツ慊ィテ」ツ?凖」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ??
            bool flag = false; 
            for(int j = 0 ; j < v.size() ; j++ ){
                int y1 = m[v[j]].first;
                int y2 = m[v[j]].second;
                
                // テ・ツ陳古ヲツ堋ヲ[1,y1] <=> ティツ・ツソテヲツ堋ヲ[y2-y1+1, y2] テ」ツ?ィテ・ツッツセテ・ツソツ愿」ツ?療」ツ?ヲテ」ツ??」ツつ?
                // テ・ツッツセテ・ツソツ愿」ツ?古」ツ?づ」ツつ凝」ツ?ィテ」ツ??
                if( y2 - y1 + 1 <= q && q <= y2 ){ 
                    flag = true;
                    int ans = q - (y2 - y1);
                    // ティツァツ」テ」ツ?ョテ・ツ?コテ・ツ環?
                    cout << v[j] << " " << ans << endl;
                    break;
                }
            }
            
            // ティツァツ」テ」ツ?古・ツュツ佚・ツ慊ィテ」ツ?療」ツ?ェテ」ツ??」ツ?ィテ」ツ??
            if( !flag ){
                cout << "Unknown" << endl;
            }
        }
    }
}

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;
            if (pt != 1) {
                if (data[0].first.first == tmp) {
                    cout << data[0].second << " " 
                        << data[0].first.second << endl;
                    fl = true;
                } else {
                    for (int j = 1; j < pt; j++) {
                        if (data[j].first.first == tmp) {
                            cout << data[j].second << " " 
                                << data[j].first.second << endl;
                            fl = true;
                            break;
                        }
                        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;
                        }
                    }
                }
            } else {
                if (data[0].first.first == tmp) {
                    cout << data[0].second << " 1" << endl;
                    fl = true;
                }
            }
            if (!fl) {
                cout << "Unknown" << endl;
            }
        }
    }
    return 0;
}