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 <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int N, Q;
  while(cin>>N>>Q && (N || Q)){
    vector<string> name(N);
    vector<int> max(N);
    vector<int> base(N);
    REP(i, N){
      cin>>name[i];
      int  y;
      cin>>max[i]>>y;
      base[i] = y - max[i];
    }
    REP(i, Q){
      int y; cin>>y;
      int h = INF;
      string era = "";
      REP(i, N){
        if(y - base[i] >= 1 && y - base[i] <= max[i]){
          h = y - base[i];
          era = name[i];
        }
      }
      if(h == INF) cout<<"Unknown"<<endl;
      else cout<<era<<" "<<h<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
string a[1000];
int b[1000];
int c[1000];
int main(){
	int n,m;
	while( cin >> n >> m && (n||m) ){
		rep(i,n){
			int x,y;
			cin >> a[i] >> x >> y;
			b[i] = y-x+1;
			c[i] = y;
		}
		rep(i,m){
			int x; cin >> x;
			bool f = false;
			rep(j,n){
				if( b[j] <= x && x <= c[j] ){
					cout << a[j] << " " << x-b[j]+1 << endl;
					f = true;break;
				}
			}
			if(!f)cout << "Unknown" << endl;
		}
	}
}

C++: #include <bits/stdc++.h>
#include <stdint.h>

typedef uint32_t u32;
typedef uint64_t u64;
typedef std::pair<int, int> pii;
constexpr int INF = (1 << 28);

int main() {

  std::string eraname[2000];
  int erabasedyear[2000];
  int westernyear[2000];
  
  for(;;) {
    int N, Q; std::cin >> N >> Q;
    if( N == 0 and Q == 0 ) break;

    for(int i = 0; i < N; ++i) {
      std::cin >> eraname[i] >> erabasedyear[i] >> westernyear[i];
    }
    for(int i = 0; i < Q; ++i) {
      int query; std::cin >> query;
      std::string era;
      int res = INF;      
      for(int j = 0; j < N; ++j) {
        if( query > westernyear[j] ) continue;
        auto t = query - westernyear[j] + erabasedyear[j];
        if( t <= 0 ) continue;
        if( t < res ) {
          res = t;
          era = eraname[j];
        }
      }
      if( res == INF ) {
        std::cout << "Unknown" << std::endl;
      }
      else {
        std::cout << era << ' ' << res << std::endl;
      }
    }    
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

struct era{
    string eraname;
    int year,order;
};

int main(){
    while(1){
        int n,q;
        cin >> n >> q;
        if(n==0 && q==0) break;
        vector<era> eras(n);
        vector<int> year(q);
        rep(i,n) cin >> eras[i].eraname >> eras[i].order >> eras[i].year;
        rep(i,q) cin >> year[i];


        rep(i,q){
            string ans = "Unknown";
            int y = -1;
            int mn = INF;
            rep(j,n){
                if(year[i] > eras[j].year || eras[j].order - eras[j].year + year[i] <= 0) continue;

                if(eras[j].year - year[i] < mn){
                    mn = eras[j].year - year[i];
                    y = eras[j].order - eras[j].year + year[i];
                    ans = eras[j].eraname;
                }
            }

            cout << ans;
            if(y!=-1) cout << " " << y << endl;
            else cout << endl;
        }
    }
    return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	for (int N, Q; cin >> N >> Q&&N;) {
		set<pair<int, int>> st;
		vector<string> name(N);
		vector<int> B(N);
		rep(i, 0, N) {
			int b, y; cin >> name[i] >> b >> y;
			st.insert(pair<int, int>(y - b + 1, i));
			B[i] = b;
		}
		rep(i, 0, Q) {
			int y; cin >> y;
			auto it = st.upper_bound(pair<int, int>(y, INF));
			if (it == st.begin()) {
				cout << "Unknown" << endl;
			}
			else {
				--it;
				int id = it->second;
				y = y - it->first + 1;
				if (y <= B[id]) {
					cout << name[id] << " " << y << endl;
				}
				else {
					cout << "Unknown" << endl;
				}
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define INF 1000000001
using namespace std;
typedef tuple<int, int, string> TP;

int main()
{
	int N, Q, EY,WY;
	string EN;
	while (cin >> N >> Q, N || Q) {
		vector<TP> Eras(N);
		for (int i = 0; i < N; i++) {
			cin >> EN >> EY >> WY;
			get<0>(Eras[i]) = WY - EY + 1;
			get<1>(Eras[i]) = WY;
			get<2>(Eras[i]) = EN;
		}
		for (int i = 0, q; i < Q; i++) {
			cin >> q;
			auto up = upper_bound(Eras.begin(), Eras.end(), TP(q, INF, string()));
			if (up == Eras.begin() || get<0>(*(up - 1)) > q || get<1>(*(up - 1)) < q)
				cout << "Unknown" << endl;
			else
				cout << get<2>(*(up - 1)) << ' ' << (q - get<0>(*(up - 1)) + 1) << endl;
		}
	}
	return 0;
}

C++: #include <vector>
#include <string>
#include <iostream>
using namespace std;
int main(){
	int N,Q,i,x,y;
	string s;
	for(;cin>>N>>Q,N;){
		vector<pair<pair<int,int>,string> >v;
		for(i=0;i<N;i++)cin>>s>>x>>y,v.push_back(make_pair(make_pair(y-x,y),s));
		for(i=0;i<Q;i++){
			cin>>x;
			for(y=0;y<N;y++)if(v[y].first.first<x&&x<=v[y].first.second)break;
			if(y==N)cout<<"Unknown"<<endl;
			else cout<<v[y].second<<' '<<x-v[y].first.first<<endl;
		}
	}
}