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)
	}
}

Python: while True:
  Name=[]
  first=[]
  final=[]
  N,Q =map(int,input().split())
  if N==Q==0:
    break
  else:
    for n in range(N):
      eraname,erabasedyear,westernyear=input().split()
      Name.append(eraname)
      era_first=int(westernyear) - int(erabasedyear) +1
      first.append(int(era_first))
      final.append(int(westernyear))
    for q in range(Q):
        year=int(input())
        count=0
        for n in range(N):
          if first[n] <= year <=final[n]:
            era_year = year -first[n] +1
            print(Name[n],era_year)
            count+=1
        if count==0:
          print("Unknown")

Python: inputnum,outputnum = (int(n) for n in input().split(' '))
while True:
    data = {}
    for i in range(inputnum):
        temp = input().split(' ')
        data[temp[0]] = [int(temp[2]) - int(temp[1]) + 1,int(temp[2])]
    for o in range(outputnum):
        targ = int(input())
        for k,v in data.items():
            if v[0] <= targ  <= v[1]:
                print(k + ' ' + str(targ-v[0] + 1))
                break
        else:
            print("Unknown")
    inputnum,outputnum = (int(n) for n in input().split(' '))
    if inputnum == outputnum == 0:
        break

Python: import bisect
while True:
    N,Q = map(int,input().split())
    if N == 0: break
    src = []
    for i in range(N):
        n,l,y = input().split()
        src.append((int(y), int(l), n))
    src.sort()
    for i in range(Q):
        q = int(input())
        a = bisect.bisect(src,(q,-1,-1))
        if a < N:
            y,l,n = src[a]
            if y-l < q <= y:
                print(n + ' ' + str(q-y+l))
                continue
        if a+1 < N:
            y,l,n = src[a+1]
            if y-l < q <= y:
                print(n + ' ' + str(q-y+l))
                continue
        print('Unknown')

Python: while True:
    n,m= map(int,input().split())
    if n==0 and m==0:
        break
    hajime= {}
    owari= {}
    for _ in range(n):
        a,b,c= input().split()
        hajime[a]= int(c)- int(b)
        owari[a]= int(c)

    for _ in range(m):
        year= int(input())
        for a in hajime:
            flag= True
            if hajime[a]< year and year<= owari[a]:
                flag= False
                print(a,year- hajime[a])
                break
        if flag:
            print("Unknown")

Python: from bisect import bisect_left


while True:
	N, Q = map(int, input().split(' '))
	if N == 0:
		break

	era = {} # Like {1877: ('Meiji', 10)}

	years = [] # 西暦
	for _ in range(N):
		name, j, w = input().split(' ')
		j, w = int(j), int(w)
		era[w] = (name, j)
		years.append(w)
	years.sort()

	for _ in range(Q):
		q = int(input())
		i = bisect_left(years, q)
		if i >= len(years):
			print('Unknown')
			continue
		y = years[i]
		name, length = era[y]
		if q - y + length <= 0:
			print('Unknown')
		else:
			print(name + ' ' + str(q-y+length))

Python: inputnum,outputnum = (int(n) for n in input().split(' '))
data = {}
while True:
    for i in range(inputnum):
        temp = input().split(' ')
        data[temp[0]] = [int(temp[2]) - int(temp[1]) + 1,int(temp[2])]
    for o in range(outputnum):
        targ = int(input())
        for k,v in data.items():
            if v[0] <= targ  <= v[1]:
                print(k + ' ' + str(targ-v[0] + 1))
                break
        else:
            print("Unknown")
    inputnum,outputnum = (int(n) for n in input().split(' '))
    if inputnum == outputnum == 0:
        break

Python: import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    dd = [(1,1),(1,0),(0,1),(0,-1),(-1,0),(-1,-1)]

    while True:
        n,q = LI()
        if n == 0 and q == 0:
            break
        a = [LS() for _ in range(n)]
        a = [[_[0],int(_[1]),int(_[2])] for _ in a]
        b = [I() for _ in range(q)]
        for c in b:
            r = 'Unknown'
            for l,e,w in a:
                if w-e < c <= w:
                    r = '{} {}'.format(l, e-w+c)
            rr.append(r)

    return '\n'.join(map(str, rr))


print(main())

C++: #include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(){
  int N, Q;
  while(cin >> N >> Q, N){
    map<int, string> M;
    map<string, int> E;
    string eraname;
    int eb, w;
    for(int i = 0; i < N; ++i){
      cin >> eraname >> eb >> w;
      M[w-eb] = eraname;
      E[eraname] = w;
    }
    for(int i = 0; i < Q; ++i){
      cin >> w;
      int t = 0;
      eraname = "Unknown";
      for(map<int, string>::iterator iter = M.begin(); iter != M.end(); ++iter){
	if(iter->first < w && w <= E[iter->second]){
	  eraname = iter->second;
	  t = w - iter->first;
	}else if(iter->first >= w) break;
      }
      cout << eraname;
      if(t) cout << " " << t;
      cout << endl;
    }
  }
  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;
		map<string, int>m;
		rep(i, n) {
			string s;
			int j, k;
			cin >> s >> j >> k;
			mp[k - j] = s;
			m[s] = j;
		}
		rep(i, q) {
			int d; scanf("%d", &d);
			auto it = mp.lower_bound(d);
			it--;
			if (it == --mp.begin()) {
				puts("Unknown");
				continue;
			}
			if (d - (*it).first > m[(*it).second]) {
				puts("Unknown");
				continue;
			}
			cout << (*it).second << ' ' << d - (*it).first << endl;
		}
	}
}