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 <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

int n, q;

class node
{
public:
	string name;
	int start, end;

	node(string n, int a, int b):name(n), start(b-a+1), end(b){}

	bool is_in_range(int year)
	{
		return start <= year && year <= end;
	}
};

int main(void)
{
	while(cin >> n >> q, n|q) {
		vector<node> vs;
		rep(i, n) {
			string name;
			int erabased, westernyear;
			cin >> name >> erabased >> westernyear;
			vs.push_back(node(name, erabased, westernyear));
		}

		rep(i, q) {
			int year;
			cin >> year;
			bool f = false;
			rep(j, vs.size())
				if(vs[i].is_in_range(year)) {
					printf("%s %d\n", vs[i].name.c_str(), year-vs[i].start+1);
					f = true;
					break;
				}
			if (!f)
				printf("Unkown\n");
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;

string name[1002];
int base[1002], west[1002];

int main(){
  int n, m;

  while(cin >> n >> m, n || m){
    for(int i = 0; i < n; i++){
      cin >> name[i] >> base[i] >> west[i];
    }
    for(int i = 0; i < m; i++){
      int x;
      cin >> x;

      bool flg = false;

      for(int j = 0; j < n; j++){
        int base_west = west[j] - base[j] + 1;

        if(base_west <= x && x <= west[j]){
          flg = true;
          cout << name[j] << " " << x - base_west + 1 << endl;
          break;
        }
      }

      if(!flg) cout << "Unknown" << endl;
    }
  }
}

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

int N,Q;

struct Data {
    int a,b;
    string ss;
    Data() {};
    Data(int a,int b,string ss) :
        a(a),b(b),ss(ss) {};

    bool operator<(const Data& data_) const {
        return (data_.b) > (b);
    }
    bool operator<(const int& val) const {
        return val > b;
    }
};

void solve() {
    Data data[1003];

    rep(i,N) {
        int a,b;
        string ss;
        cin>>ss>>a>>b;

        data[i] = Data(a,b,ss);
    }
    sort(data,data+N);

    rep(i,Q) {
        int a;
        cin>>a;
        int pos = lower_bound(data,data+N, a) - data;
        if(pos ==N) {
            cout<<"UnKnown"<<endl;
            continue;
        }
        int t = a - (data[pos].b-data[pos].a);
        if(t <= 0) {
            cout<<"UnKnown"<<endl;
            continue;
        }
        cout<<data[pos].ss<<" "<<t<<endl;


        
        
    }


}

int main() {
    while(cin>>N>>Q) {
        if(N+Q==0) return 0;
        solve();
    }

    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;

string name[1000];
int era[1000];
int west[1000];
int main(){
	int n,q;
	while(cin>>n>>q,n|q){
		for(int i=0;i<n;i++)
			cin>>name[i]>>era[i]>>west[i];
		for(int i=0;i<q;i++){
			int a;
			cin>>a;
			bool f=false;
			for(int j=0;j<n;j++){
				if(west[j]-era[j]+1<=a&&a<=west[j]){
					cout<<name[j]<<' '<<a-(west[j]-era[j])<<endl;
					f=true;
					break;
				}
			}
			if(!f)cout<<"Unknown"<<endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,string> P;
typedef pair<int,P > PP;

int main(){
  int n,q;
  while(cin>>n>>q,n+q){
    PP pr[1010];
    for(int i=0;i<n;i++){
      string s;
      int a,b;
      cin>>s>>a>>b;
      pr[i]=PP(b,P(a,s));
    }
    pr[n]=PP(1e9+1,P(0,"a"));
    sort(pr,pr+n+1);
    for(int i=0;i<q;i++){
      int x;
      cin>>x;
      int ok=n,ng=-1,mid;
      while(ok-ng>1){
	mid=(ok+ng)/2;
	if(pr[mid].first>=x)ok=mid;
	else ng=mid;
      }
      int t=pr[ok].first-x;
      int k=pr[ok].second.first;
      if(t<k)cout<<pr[ok].second.second<<" "<<k-t<<endl;
      else cout<<"Unknown"<<endl;
    }
  }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
struct era{
  int s,e;
  string name;
  bool operator<(const era&e)const{
    return s < e.s;
  }
};
int main(){
  int n,q;
  int i,j,k;
  era e;
  string str;
  int b,w;
  cin >> n >> q;
  while(n+q!=0){
    vector<era> v;
    for(i=0;i<n;i++){
      cin >> str >> b >> w;
      e.name=str;
      e.s=w-b+1;e.e=w;
      v.push_back(e);
    }
    sort(v.begin(),v.end());
    for(i=0;i<q;i++){
      cin >> b;
      int st=0,en=v.size()-1,no;
      no=(st+en)/2;
      for(j=0;j<100;j++){
	if(v[no].s<b) st = no;
	else en=no;
	no=(st+en)/2;
      }
      if(v[no].s<=b&&b<=v[no].e) cout << v[no].name <<" "<<  (b-v[no].s+1) << endl;
      else cout << "Unknown" << endl;
    }
    
    cin >> n >> q;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

vector<pair<int, pair<int, string> > > data;

int val;

int get_era(int q){
  int tmp = -1;
  for(int i=0;i<data.size();i++){
    if(data[i].first <= q && q <= (data[i].second).first){
      val = q-data[i].first;
      return i;
    }
  }
  return -1;
}

main(){
  int N, Q;
  while(cin >> N >> Q){
    if(N == 0 && Q == 0) break;
    data.clear();
    for(int i=0;i<N;i++){
      string name;
      int era, west;
      cin >> name >> era >> west;
      data.push_back(make_pair(west-era+1, make_pair(west, name)));
    }
    sort(data.begin(), data.end());
    for(int i=0;i<Q;i++){
      int q, ans;
      cin >> q;
      ans = get_era(q);
      if(ans == -1) cout << "Unknown" << endl;
      else cout << (data[ans].second).second << ' ' << val+1 << endl;
    }
  }
  return 0;

}

C++: #include<iostream>
#include<string>
using namespace std;

typedef struct{
  string name;
  long long start;
  long long end;
}Era;

int main()
{
  Era E[10000];
  int N,Q,s;

  while(1){
    cin>>N>>Q;
    if(N==0&&Q==0)break;
    for(int i=0;i<N;i++){
      cin>>E[i].name>>s>>E[i].end;
      E[i].start=(E[i].end-s);
    }
    for(int i=0;i<Q;i++){
      cin>>s;
      for(int j=0;j<N;j++){
	if(E[j].start<s && s<E[j].end){
	  cout<<E[j].name<<" "<<(s-E[j].start)<<endl;
	  break;
	}
        if(j==N-1)cout<<"Unkown"<<endl;
      }
    }
  }
  return 0;
}