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 <string>
#include <map>

int main() {
    int n, q;

    while(1) {
        std::cin >> n >> q;
        if(n * q == 0) {
            return 0;
        }

        std::map<int, std::pair<int, std::string>> m;
        for(int i = 0; i < n; ++i) {
            std::string  name;
            int b , w;
            std::cin >> name >> b >> w;

            m[w - b + 1] = {w, name};
        }

        for(int i = 0; i < q; ++i) {
            int k;
            std::cin >> k;

            std::string contained = "";
            int year;
            for(auto&& p : m) {
                if(p.first <= k && p.second.first >= k) {
                    if(contained != "") {
                        std::cout << "Unknown" << std::endl;
                        goto END;
                    }

                    contained = p.second.second;
                    year = k - p.first + 1;
                }
            }

            if(contained == "") {
                std::cout << "Unknown" << std::endl;
            }else {
                std::cout << contained << " " << year << std::endl;
            }
            END:;
        }
    }
}

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

using namespace std;

typedef struct names {
	string en;
	int eby;
	int wy;
};

/*
void sort(names array[], int S) {
	int sorted, last;
	int i;
	names temp;

	sorted = S;
	while(sorted) {
		last = 0;
		for(i = 0; i < sorted - 1; i++) {
			if(array[i].wy > array[i + 1].wy) {
				temp = array[i];
				array[i] = array[i + 1];
				array[i + 1] = temp;
				last = i + 1;
			}
		}

		sorted = last;
	}
}
*/

bool comp(names A, names B) {
	return A.wy < B.wy;
}

int main(void) {
	int N, Q;
	names data[1024];
	int query;
	int next;

	while(cin >> N >> Q, N != 0 || Q != 0) {
		for(int i = 0; i < N; i++)
			cin >> data[i].en >> data[i].eby >> data[i].wy;
		sort(data, data + N, comp);
		
		for(int i = 0; i < Q; i++) {
			cin >> query;
			for(next = 0; query > data[next].wy && next < N; next++);
			if(next == N) {
				cout << "Unknown" << endl;
				continue;
			}

			if(data[next].eby + query - data[next].wy > 0)
				cout << data[next].en << " " << data[next].eby + query - data[next].wy << endl;
			else
				cout << "Unknown" << endl;
		}
	}
}

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

int main() {
	int n, q;
	while (scanf("%d%d", &n, &q), n) {
		map<int, string>mp;
		rep(i, n) {
			string s;
			int j, k;
			cin >> s >> j >> k;
			mp[k - j] = s;
		}
		rep(i, q) {
			int d; scanf("%d", &d);
			auto it = mp.lower_bound(d);
			if ((*it).first == d) {
				puts("Unknown");
				continue;
			}
			it--;
			if (it == --mp.begin()) {
				puts("Unknown");
				continue;
			}
			cout << (*it).second << ' ' << d - (*it).first << endl;
		}
	}
}

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

int main() {
    while (true) {
        int n, q;
        cin >> n >> q;
        if ((n | q) == 0) {
            break;
        }
        map<int, pair<int, string> > eras;
        vector<int> firstYears;
        for (int i = 0; i < n; i++) {
            string eraName;
            int eraBasedYear, westernYear;
            cin >> eraName >> eraBasedYear >> westernYear;
            int firstYear = westernYear - eraBasedYear + 1;
            eras.insert(make_pair(firstYear, make_pair(westernYear, eraName)));
            firstYears.push_back(firstYear);
        }
        sort(firstYears.begin(), firstYears.end());
        for (int i = 0; i < q; i++) {
            int year;
            cin >> year;
            int firstYear = -1;
            for (int i = n - 1; i >= 0; i--) {
                if (firstYears[i] <= year) {
                    firstYear = firstYears[i];
                    break;
                }
            }
            if (firstYear < 0 || eras[firstYear].first < year) {
                cout << "Unknown" << endl;
            } else {
                cout << eras[firstYear].second << " " << year - firstYear + 1 << endl;
            }
        }
    }
}

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

using namespace std;

int main()
{
    int N, Q;

    while (cin >> N >> Q, N || Q) {
        vector<pair<int, string> > memo;

        for (int i = 0; i < N; i++) {
            string s;
            int ey, wy;

            cin >> s >> ey >> wy;
            memo.push_back(make_pair(wy - ey, s));
        }
        sort(memo.begin(), memo.end());


        for (int i = 0; i < Q; i++) {
            int q;

            cin >> q;
            bool flag = false;
            for (int j = 0; j < N - 1; j++) {
                if (memo[j].first + 1 <= q && memo[j + 1].first > q) {
                    flag = true;
                    cout << memo[j].second << " " << q - memo[j].first << endl;
                    break;
                }
            }

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

    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>
#define MAX_N 1000
#define INF 2000000000
using namespace std;

string eraname[MAX_N];
int erabased[MAX_N], western[MAX_N];
int erafirst[MAX_N];

void search(int y, int n) {
  if (y < erafirst[0]) {
    cout << "Unknown" << endl;
    return;
  }
  for (int i = 1; i - 1 < n; i++) {
    if (y < erafirst[i]) {
      int temp = y - erafirst[i - 1] + 1;
      if (temp > erabased[i - 1]) {
	cout << "Unknown" << endl;
	return;
      } else {
	cout << eraname[i - 1] << ' ' << temp << endl;
	return;
      }
    }
  }
  cout << "Unknown" << endl;
  return;
}

void era_sort(int n) {
  for (int i = 0; i < n; i++) {
    for (int j = i; j > 0; j--) {
      if (erafirst[j - 1] > erafirst[j]) {
	swap(eraname[j - 1], eraname[j]);
	swap(erabased[j - 1], erabased[j]);
	swap(erafirst[j - 1], erafirst[j]);
	swap(western[j - 1], western[j]);
      }
    }
  }
}

void init() {
  for (int i = 0; i < MAX_N; i++) {
    eraname[i] = erabased[i] = western[i] = 0;
    erafirst[i] = INF;
  }
}

int main() {
  while (true) {
    int n, q;
    cin >> n >> q;
    if (n == 0 && q == 0) return 0;

    init();

    for (int i = 0; i < n; i++) {
      cin >> eraname[i] >> erabased[i] >> western[i];
    }

    for (int i = 0; i < n; i++) {
      erafirst[i] = western[i] - erabased[i] + 1;
    }

    era_sort(n);

    for (int i = 0; i < q; i++) {
      int query;
      cin >> query;

      search(query, n);
    }
  }
}