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;

int main(){

    while(1){
        int n, q; cin >> n >> q;
        if(!n && !q) break;
        map<string, pair<long long, long long> > era;
        
        string s[1000];
        for(int i = 0; i < n; i++){
            long long by, wy;
            cin >> s[i] >> by >> wy;
            era[s[i]] = make_pair(wy - (by - 1), wy);
        }

        for(int i = 0; i < q; i++){
            long long qu; cin >> qu;
            for(int j = 0; j < n; j++){
                if(era[s[j]].first <= qu && era[s[j]].second >= qu){
                    cout << s[j] << " " << qu + 1 - era[s[j]].first << endl;
                    break;
                }else if(j == n - 1){
                    cout << "Unknown" << endl;
                }
            }
        }
    }
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

struct node{
    char en[20];
    int year;
}q[1005];

int cmp(node a,node b){
    return a.year<b.year;
}

int main()
{
    int n,Q;
    while(~scanf("%d%d",&n,&Q)){
        if(n==0 && Q==0) break;
        int i,j;
        for(i=0;i<n;i++){
            int t1,t2;
            scanf("%s%d%d",q[i].en,&t1,&t2);
            q[i].year=t2-t1;
        }
        sort(q,q+n,cmp);
        while(Q--){
            int tmp;
            scanf("%d",&tmp);
            for(i=n-1;i>=0;i--){
                if(tmp-q[i].year==0 && i!=0){
                    i=-1;
                    break;
                }
                if(tmp-q[i].year>=1)
                    break;
            }
            if(i==-1){
                puts("Unknown");
                continue;
            }
            else{
                printf("%s %d\n",q[i].en,tmp-q[i].year);
            }
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
using namespace std;
struct item{
	string name;
	int year;
	int value;
};
int main(){
	int n,m,a,b;
	item x;
	string s;
	vector<item> v;
	bool check;
	while(1){
		cin >> n >> m;
		if(n == 0)break;
		v.clear();
		for(int i = 0;i < n;i++){
			cin >> s >> a >> b;
			x.name = s;
			x.year = b;
			x.value = a;
			v.push_back(x);
		}
		for(int i = 0;i < m;i++){
			check = false;
			cin >> a;
			for(int j = 0;j < v.size();j++){
				if(v[j].year >= a && v[j].year - v[j].value < a){
					cout << v[j].name << " " << a - (v[j].year - v[j].value) << endl;
					check = true;
				}
			}
			if(!check)cout << "Unknown" <<endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> P;

int main() {
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
	int n, q;
	while(cin >> n >> q && (n || q)){
		map<string, P> m;
		string s;
		int b, w, y;
		for(int i = 0; i < n; ++i){
			cin >> s >> b >> w;
			m[s] = P(w - b + 1, w);
		}
		for(int i = 0; i < q; ++i){
			cin >> y;
			bool ok = false;
			for(auto& v : m){
				if(v.second.first <= y && y <= v.second.second){
					cout << v.first << " " << y - v.second.first + 1 << endl;
					ok = true;
				}
			}
			if(!ok)
				cout << "Unknown" << endl;
		}
		m.clear();
	}
	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<ll, ll> P;
int main()
{
  int N, Q;
  while(cin>>N>>Q,N||Q) {
    map<ll, string> era; // ?????????????????´, ?????£?????????
    map<ll, ll> year; // ?????????????????´, ?§???????????????´
    ll start = 1e15;
    ll last = 0;
    FOR(i,0,N) {
      string s;
      ll a, b;
      cin >> s >> a >> b;
      era[b] = s;
      year[b] = b - a + 1;
      start = min(start, b - a + 1);
      last = max(last, b);
    }
    FOR(i,0,Q) {
      ll in; cin >> in;
      auto y = era.lower_bound(in);
      string e = y->second;
      ll st = year[y->first];
      if(in < start || last < in)
        cout << "Unknown" << endl;
      if(st <= in && y->first >= in) {
        cout << e << " " << in - st + 1 << endl;
      } else {
        puts("Unknown");
      }
    }
  }
  return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<pair<string,pii> > v(n);
		rep(i,n){
			cin>>v[i].F>>v[i].S.F>>v[i].S.S;
		}
		rep(i,m){
			int t;
			cin>>t;
			bool f=true;
			rep(j,n){
				if(v[j].S.S>=t&&v[j].S.S-v[j].S.F+1<=t){
					cout<<v[j].F<<" "<<v[j].S.F-(v[j].S.S-t)<<endl;
					f=false;
					break;
				}
			}
			if(f) cout<<"Unknown\n";
		}
	}
}



}
main() try{
    mainmain();
}
catch(...){
}