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 <cstring>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long LL;
const int N=100000;

struct data {
    char name[20];
    LL ss, tt;
    void init(char _name[], LL _ss, LL _tt) {
        strcpy(name, _name);
        ss=_ss, tt=_tt;
    }
} A[N];

int n, m;

int main() {
//freopen("/home/lovezzt/桌面/in.txt", "r", stdin);
    while(~scanf("%d%d", &n, &m)) {
        if(n == 0 && m == 0){
            break;
        }
        for(int i=0; i<n; i++) {
            char name[20];
            LL y1, y2;
            scanf("%s%lld%lld", name, &y1, &y2);
           // cout << y1 << " " << y2 << endl;
            A[i].init(name, y2-y1+1, y2);
        }
        while(m--) {
            LL y;
            scanf("%lld", &y);
            bool flag=1;
            for(int i=0; i<n; i++) {
                if(A[i].ss<=y && A[i].tt>=y) {
                    printf("%s %lld\n", A[i].name, (y-A[i].ss)+1);
                    flag=0;
                    break;
                }
            }
            if(flag) printf("Unknown\n");
        }
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n, q;
	while (scanf("%d%d", &n, &q), n) {
		map<int, string>mp;
		rep(i, n) {
			string s;
			int j, k;
			cin >> s >> j >> k;
			mp[k - j] = s;
		}
		rep(i, q) {
			int d; scanf("%d", &d);
			auto it = mp.lower_bound(d);
			it--;
			if (it == --mp.begin()) {
				puts("Unknown");
				continue;
			}
			if ((*it).first == d) {
				puts("Unknown");
				continue;
			}
			if (it != --mp.end()) {
				if ((*++it).first - d == 1) {
					puts("Unknown");
					continue;
				}
				else it--;
			}
			cout << (*it).second << ' ' << d - (*it).first << endl;
		}
	}
}