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

int n , q;
struct T{
    char year[30];
    int day;
    int y;
}node[1005];

int cmp(const void *a , const void *b){
    struct T *c = (T *)a;
    struct T *d = (T *)b;
    if(c->y < d->y) return true;
    return false;
}


int main(){

    int t , temp;
    bool flag;
	while(~scanf("%d%d" , &n , &q) && n || q){

        for(int i = 0 ; i < n ; i ++){
            scanf("%s%d%d" , node[i].year , &node[i].day , &node[i].y);
        }
        //qsort(node , n , sizeof(node[0]) , cmp);

        for(int i = 0 ; i < q ; i ++){
            scanf("%d" , &t);flag = false;
            for(int j = 0 ; j < n ; j ++){
                if(t >= node[j].y - node[j].day + 1 && t <= node[j].y){
                    printf("%s %d\n" , node[j].year , node[j].day - (node[j].y - t));
                    flag = true;
                    break;
                }
            }
            if(flag == false) printf("Unknown\n");
        }


	}

	return 0;
}