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;

        auto last = dict.begin();
        for(int i=0; i<n; i++) {
            string name;
            int base, west;
            cin >> name >> base >> west;
            dict[west-base+1] = name;
            max[name] = base;
            if(last->first > west-base+1)
                last = dict.find(west-base+1);
        }
        for(int i=0; i<q; i++) {
            int y;
            cin >> y;
            auto it = dict.upper_bound(y);
            if(it == dict.end())
                it = last;
            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<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

typedef struct{
  string name;
  int start;
  int goal;
} Data;

bool operator<(const Data &d1,const Data &d2){
  return (d1.start < d2.start);
}

int main(){
  int n,q;
  while(cin>>n>>q,n){
    vector<Data> vec(n);
    for(int i=0;i<n;i++){
      Data d;
      int diff;
      cin>>d.name>>diff>>d.goal;
      d.start=d.goal-diff+1;
      vec[i]=d;
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<q;i++){
      int num;
      cin>>num;
      for(int j=0;j<n;j++){
	if(vec[j].start <= num){
	  if(num <= vec[j].goal){
	    cout<<vec[j].name<<" "<<num-vec[j].start+1<<endl;
	    break;
	  }
	}else{
	  cout<<"Unknown"<<endl;
	  break;
	}
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

string name[1000];
int num[1000];
int year[1000];
int n,q;

int main() {
  while(cin >> n >> q, n||q) {
    REP(i,n) {
      cin >> name[i] >> num[i] >> year[i];
    }
    REP(i,q) {
      int y;cin >> y;
      bool f = 0;
      REP(j,n) {
        if (year[j]-num[j]+1 <= y && y<=year[j]) {
          cout << name[j] << " " << y-year[j]+num[j] << endl;
          f = 1;
          break;
        }
      }
      if (!f) cout << "Unknown" << endl;
    }  
  }
}

C++: #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Era {
  string name;
  ll start;
  ll span;
  Era() {;}
  Era(string name, int start, int span) : name(name), start(start), span(span) {;}
  bool operator<(const Era &rhs) const {
    return start < rhs.start;
  }
};

int main() {
  int n, m;
  while (scanf("%d %d", &n, &m), n|m) {
    set<Era> eras;
    REP(i, n) {
      string str;
      int span, start;
      cin >> str >> span >> start;
      eras.insert(Era(str, -start + span - 1, span));
    }
    REP(i, m) {
      int t;
      cin >> t;
      set<Era>::iterator it = eras.lower_bound(Era("", -t, 0));
      if (it == eras.end()) {
        puts("Unknown");
      } else {
        int s = t - -it->start;
        if (s < it->span) {
          cout << it->name << " " << s + 1 << endl;
        } else {
          puts("Unknown");
        }
      }
    }
  }
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

int main()
{
    int n,m;
    while(cin >> n >> m) {
        if(n == 0 && m == 0) break;
        
        map<string,pair<int,int> > ma;
        
        rep(i,n) {
            string s;
            int a,b;
            cin >> s >> a >> b;
            
            ma[s] = make_pair(b-a+1,b);
        }

        rep(i,m) {
            int x;
            cin >> x;
        
            bool flag = true;
            map<string,pair<int,int> >::iterator ite;
            for(ite = ma.begin();ite != ma.end();ite++) {
                int s = ite->second.first;
                int e = ite->second.second;

                if(s <= x && x <= e) {
                    cout << ite->first << " " << x - s + 1 << endl;
                    flag = false;
                    break;
                }
            }

            if(flag) cout << "Unknown" << endl;
        }
    }

    return 0;
}

C++: #include<iostream>

using namespace std;

void hoge(int N, int Q){

   string a[N];
   int b[N], c[N], d[2*N];
   for(int i=0; i<N; i++){
      cin>> a[i]>> b[i]>> c[i];
      d[2*i]=c[i]-b[i]+1;
      d[2*i+1]=c[i];
   }

   for(int q=0; q<Q; q++){
      int e;
      cin>> e;
      for(int i=0; i+1<2*N; i+=2){
         if(d[i]<=e&&e<=d[i+1]){
            cout<< a[i/2]<< " "<< e-d[i]+1<< endl;
            goto ikd;
         }
      }
      cout<< "Unknown"<< endl;
      ikd:;
   }
}

int main(){

   while(1){
      int N, Q;
      cin>> N>> Q;
      if(!(N||Q)) break;

      hoge(N, Q);
   }

   return 0;
}