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<map>
#include<vector>
#include<set>
#include<iostream>

using namespace std;


int main(void) {
    while(1) {
        map<int,string> dict;
        map<string,int> max;
        int n,q;
        cin >> n >> q;
        if(!n) break;
        for(int i=0; i<n; i++) {
            string name;
            int base, west;
            cin >> name >> base >> west;
            dict[west-base+1] = name;
            max[name] = base;
        }
        for(int i=0; i<q; i++) {
            int y;
            cin >> y;
            auto it = dict.upper_bound(y);
            if(it == dict.end())
                it = dict.lower_bound(y);
            else if(it == dict.begin()) {
                cout << "Unknown" << endl;
                continue;
            }
            else
                it--;

            if((y-it->first+1) > max[it->second])
                cout << "Unknown" << endl;
            else
                cout << it->second << ' ' << y-(it->first)+1 << endl;
        }

    }
    return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
char s[1010][20];
int l[1010],r[1010];
int main()
{
    int n,m;
    while (scanf("%d%d",&n,&m)==2)
    {
        if (n==0&&m==0) break;
        for (int i=0;i<n;i++)
        {
            scanf("%s",s[i]);
            scanf("%d%d",&l[i],&r[i]);
            l[i]=r[i]-l[i]+1;
        }
        while (m--)
        {
            bool sol=false;
            int x,id=0,cnt=0;
            scanf("%d",&x);
            for (int i=0;i<n;i++)
            {
                if (l[i]<=x&&r[i]>=x)
                {
                    id=i;
                    cnt++;
                    sol=true;
                }
            }
            if (!sol||cnt>1) puts("Unknown");
            else
                printf("%s %d\n",s[id],x-l[id]+1);
        }
    }
    return 0;
}

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

using namespace std;

struct Era {
  string eraName;
  int firstYear;
  int endYear;
};

int checkEra(const vector<Era> &eraVec, int year, string& era)
{
  
  for (int i = 0; i < eraVec.size(); i++) {
    if (year >= eraVec[i].firstYear &&
        year <= eraVec[i].endYear) {
      era = eraVec[i].eraName;
      return year - eraVec[i].firstYear + 1;
    }
  }
  era = "Unknown";
  return 0;     
}

int main()
{
  int n, q;
  string eraName;
  int eraBasedYear, westernYear;
  vector<Era> eraVec;
  int query;
  
  while (1) {
    cin >> n >> q;
    if (n == 0 && q == 0) break;
    eraVec.clear();
    for (int i = 0; i < n; i++) {
      cin >> eraName >> eraBasedYear >> westernYear;
      cin.ignore();
      Era tempEra;
      tempEra.eraName = eraName;
      tempEra.firstYear = westernYear - eraBasedYear + 1;
      tempEra.endYear = westernYear;
      eraVec.push_back(tempEra);
    }
    for (int i = 0; i < q; i++) {
      cin >> query;
      string era;
      int year;
      year = checkEra(eraVec, query, era);
      if (year) {
        cout << era << " " << year << endl;
      } else {
        cout << era << endl;
      }
    }
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a||b){
    vector<string>in(a);
    vector<int>in1(a);
    vector<int>in2(a);
    rep(i,a)cin>>in[i]>>in1[i]>>in2[i];
    rep(q,b){
      int n;
      cin>>n;
      bool h=false;
      rep(i,a){
	if(in2[i]-in1[i]<n&&n<=in2[i]){
	  h=true;
	  cout<<in[i]<<" "<<n-in2[i]+in1[i]<<endl;
	  break;
	}
      }
      if(!h)cout<<"Unkown"<<endl;
    }
  }
}

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

int main(){
  int n,q,i;
  int j,b[1010],e[1010],y;
  string name[1010];

  while(cin >> n >> q, n+q){
    for(i=0;i<n;i++){
      cin >> name[i] >> j >> e[i];
      b[i] = e[i]-j+1;
    }

    for(i=0;i<q;i++){
      cin >> y;
      for(j=0;j<n;j++){
	if(b[j]<= y && y<=e[j]){
	  cout << name[j] << " " << y-b[j]+1 << endl;
	  break;
	}
      }
      if(j==n)cout << "Unknown\n";
    }
  }
}

C++: #define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;
#define debug2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define debugg(g,h,w) rep(i,0,h) { rep(j,0,w) cout << g[i][j] << " "; cout << endl;}
#define debugv(v) for(auto&& x : v){cout << x << " ";} cout << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;
typedef pair<ll, ll> Pll;

struct era{
	string name;
	int s;
	int e;
	era(){};
	era(string _n, int _s, int _e) {name = _n, s = _s, e = _e;};
	bool operator<(const era& rhs) {
		return e < rhs.e;
	}
};
struct b {
	bool operator ()(era const& ms, int i) {
		return ms.e < i;
	}
};
era a[1010];

int main()
{
	while (1) {
		int n, q;
		cin >> n >> q;
		if (!n && !q) break;
		memset(a, 0, sizeof(a));

		rep(i,0,n) {
			string name;
			int s, e;
			cin >> name >> s >> e;
			a[i] = {name,s,e};
		}
		sort(a, a+n);
		//rep(i,0,n) cout << a[i].name << endl;

		rep(i,0,q) {
			int x;
			cin >> x;
			auto *p = lower_bound(a, a+n, x, b());
			int check = a[p-a].e - x;
			if (p-a < n && check < a[p-a].s) cout << a[p-a].name << " " << a[p-a].s-check << endl;
			else cout << "Unknown" << endl;
		}
	}
	return 0;
}