# include <bits/stdc++.h>

using namespace std;

# define ll long long

ll n, d, t[1010];
vector <pair <string, string> > ans;
string  a[1010], b[1010];
map <string, map <string, ll> > us;

int main() {
    cin >> n >> d;
    for(int i = 1;i <= n;i++) {
        cin >> a[i] >> b[i] >> t[i];
    }
    for(int i = 1;i <= n;i++) {
        for(int j = i + 1;j <= n;j++) {
            if(a[j] == b[i] && b[j] == a[i] && abs(t[j] - t[i]) <= d && abs(t[j] - t[i]) > 0) {
                if(us[a[i]][b[i]] == 0) {
                   ans.push_back({a[i], b[i]});
                   us[a[i]][b[i]] = 1;
                   us[b[i]][a[i]] = 1;
                   break;
                }
            }
        }
    }
    cout << ans.size() << '\n';
    for(int i = 0;i < ans.size();i++) {
        cout << ans[i].first << " " << ans[i].second << '\n';
    }
}


# include <bits/stdc++.h>

using namespace std;

# define ll long long

ll n, d, t[1010];
vector <pair <string, string> > ans;
string  a[1010], b[1010];

int main() {
    cin >> n >> d;
    for(int i = 1;i <= n;i++) {
        cin >> a[i] >> b[i] >> t[i];
    }
    for(int i = 1;i <= n;i++) {
        for(int j = i + 1;j <= n;j++) {
            if(a[j] == b[i] && b[j] == a[i] && abs(t[j] - t[i]) <= d && abs(t[j] - t[i]) > 0) {
                ans.push_back({a[i], b[i]});
                break;
            }
        }
    }
    cout << ans.size() << '\n';
    for(int i = 0;i < ans.size();i++) {
        cout << ans[i].first << " " << ans[i].second << '\n';
    }
}


//s#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <tuple>

using namespace std;

int main()
{
	//ifstream cin("in.txt");
	int n, x;
	cin>>n>>x;
	map<string, set<string> > m;
	vector<tuple<string, string, int> > v;
	set<pair<string, string> > ans;
	for (int i=0; i<n; i++){
		int num;
		string s1, s2;
		cin>>s1>>s2>>num;
		v.push_back(make_tuple(s1,s2,num));
	}

	for (int i=0; i<n; i++){
		int num;
		string s1, s2;
		tie(s1, s2, num) = v[i];
		for (int j=i+1; j<n; j++){
			int numj;
			string s1j, s2j;
			tie(s1j,s2j,numj) = v[j];
			if (numj - num > x) break;
			if (s1 != s2j || s2 != s1j) continue;
			m[s1j].insert(s1);
		}
	}

	auto p=m.begin();
	for(; p!=m.end(); p++){
		auto j=p->second.begin();
		string s = p->first;
		for(; j!=p->second.end(); j++){
			string s1=*j;
			ans.insert(make_pair(min(s, s1), max(s1, s)));
		}
	}

	cout<<ans.size()<<endl;
	auto it=ans.begin();
	for (; it!=ans.end(); it++){
		cout<<it->first<<" "<<it->second<<endl;
	}

}


//s#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <tuple>

using namespace std;

int main()
{
	//ifstream cin("in.txt");
	int n, x;
	cin>>n>>x;
	vector<tuple<string, string, int> > v;
	set<pair<string, string> > ans;
	for (int i=0; i<n; i++){
		int num;
		string s1, s2;
		cin>>s1>>s2>>num;
		v.push_back(make_tuple(s1,s2,num));
	}

	for (int i=0; i<n; i++){
		int num;
		string s1, s2;
		tie(s1, s2, num) = v[i];
		for (int j=i+1; j<n; j++){
			int numj;
			string s1j, s2j;
			tie(s1j,s2j,numj) = v[j];
			if (numj - num > x) break;
			if (s1 != s2j || s2 != s1j || numj==num) continue;
			ans.insert(make_pair(min(s1j, s1), max(s1, s1j)));
		}
	}

	cout<<ans.size()<<endl;
	auto it=ans.begin();
	for (; it!=ans.end(); it++){
		cout<<it->first<<" "<<it->second<<endl;
	}

}


//s#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <tuple>

using namespace std;

int main()
{
	//ifstream cin("in.txt");
	int n, x;
	cin>>n>>x;
	map<string, set<string> > m;
	vector<tuple<string, string, int> > v;
	set<pair<string, string> > ans;
	for (int i=0; i<n; i++){
		int num;
		string s1, s2;
		cin>>s1>>s2>>num;
		v.push_back(make_tuple(s1,s2,num));
	}

	for (int i=0; i<n; i++){
		int num;
		string s1, s2;
		tie(s1, s2, num) = v[i];
		for (int j=i+1; j<n; j++){
			int numj;
			string s1j, s2j;
			tie(s1j,s2j,numj) = v[j];
			if (numj - num > x) break;
			if (s1 != s2j || s2 != s1j || numj==num) continue;
			m[s1j].insert(s1);
		}
	}

	auto p=m.begin();
	for(; p!=m.end(); p++){
		auto j=p->second.begin();
		string s = p->first;
		for(; j!=p->second.end(); j++){
			string s1=*j;
			ans.insert(make_pair(min(s, s1), max(s1, s)));
		}
	}

	cout<<ans.size()<<endl;
	auto it=ans.begin();
	for (; it!=ans.end(); it++){
		cout<<it->first<<" "<<it->second<<endl;
	}

}


#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <array>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <ctime>
#include <numeric>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <complex>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <set>
#include <stack>
#include <queue>
#include <utility>
#include <chrono>

using namespace std;

using ll = long long int;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define VPii  vector< pair <int, int> > v(n*n + 1, make_pair(0, 0));
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)

template<class T> inline string tostr(const T & x)
{
	stringstream ss; ss << x; return ss.str();
}
inline ll parse(const string & s)
{
	stringstream ss(s); ll x; ss >> x; return x;
}

template <typename T>
vector<size_t> sort_indexes(const vector<T> &v) {

	// initialize original index locations
	vector<size_t> idx(v.size());
	for (size_t i = 0; i != idx.size(); ++i) idx[i] = i;

	// sort indexes based on comparing values in v
	sort(idx.begin(), idx.end(),
		[&v](size_t i1, size_t i2) {return v[i1] < v[i2]; });

	return idx;
}
int gcd(int n1, int n2) {
	return (n2 == 0) ? n1 : gcd(n2, n1 % n2);
}
int cnt_ones(int i)
{
	i = i - ((i >> 1) & 0x55555555);
	i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
	return (((i + (i >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
}
string DecToBin(int number)
{
	if (number == 0) return "0";
	if (number == 1) return "1";

	if (number % 2 == 0)
		return DecToBin(number / 2) + "0";
	else
		return DecToBin(number / 2) + "1";
}
long long int fact(int a)
{
	long long	int p = 1;
	while (a >= 1)
	{
		p = p*a;
		a--;
	}

	return p;
}

ull cnr(int n, int r)
{
	ull ans = 1;
	r = std::min(r, n - r);

	for (int j = 1; j <= r; j++, n--) {
		// all following do: ans = (ans * n) / j;
		// but the 2 first cases do some simplifications
		// to reduce the possibility of overflow

		if (n % j == 0) {
			ans *= n / j;
		}
		else if (ans % j == 0) {
			ans = (ans / j) * n;
		}
		else {
			ans = (ans * n) / j;
		}
	}
	return ans;
}

template<class T>
inline bool read(T &n)
{
	T x = 0, tmp = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
	if (c == EOF) return false;
	if (c == '-') c = getchar(), tmp = -1;
	while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
	n = x*tmp;
	return true;
}
template <class T>
inline void write(T n)
{
	if (n < 0)
	{
		putchar('-');
		n = -n;
	}
	int len = 0, data[20];
	while (n)
	{
		data[len++] = n % 10;
		n /= 10;
	}
	if (!len) data[len++] = 0;
	while (len--) putchar(data[len] + 48);
}
// generatore di 'lucky numbers' fino a 10e9
vector<ll> lucky;
#define MAX 100000000000ll
void make(ll num) {
	if (MAX < num) return;
	lucky.push_back(num);
	make(num * 10 + 4);
	make(num * 10 + 7);
}
// generatore di primi
bool prime[1000000]{ 1,1 };
void sieve() {
	for (int i = 2; i * i <= 1000000; i++)
		if (!prime[i]) {
			for (int j = i * i; j <= 1000000; j += i) prime[j] = 1;
		}
}
// trova i divisori propri
vector<int> GetDivisors(int number)
{
	vector<int>d;
	for (int i = 1; i <= sqrt(number); i++)
	{
		if (number % i == 0)
		{
			d.push_back(i);
			if (i != (number / i))
			{
				d.push_back(number / i);
			}
		}
	}
	return d;
}
// check divisibility by num of arbitrarily long string representing an integer
bool Is_divisible_by(string s, int num)
{
	int ret = 0;
	for (int i = 0; i < static_cast<int>(s.length()); i++)
		ret = (10 * ret + s[i] - '0') % num;
	return ret == 0;
}
// input a vector of T type with n elems
template<typename T>
vector<T> rv(T n)
{
	vector<T>v(n);
	for (auto &i : v)
		cin >> i;
	return v;
}
int main()
{
	//freopen("C:/input.txt", "r", stdin);
	//freopen("C:/output.txt","w",stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int n, d;
	cin >> n >> d;
	vector<string>from(n), to(n);
	vector<int>t(n);
	set<string>friends;
	for (size_t i = 0; i < n; i++)
		cin >> from[i] >> to[i] >> t[i];
	for (size_t i = 0; i < n; i++)
	{
		for (size_t j = i + 1; j < n; j++)
		{
			if (from[i] == to[j] && to[i] == from[j] && t[j] - t[i]>0 && t[j] - t[i] <= d)
			{
				friends.insert(to[i] + "$" + from[i]);
			}
		}
	}
	cout << friends.size() << "\n";
	for (auto &item : friends)
	{
		string hoc = item;
		string delimiter = "$";
		size_t pos = 0;
		std::string token;
		while ((pos = hoc.find(delimiter)) != std::string::npos) {
			token = hoc.substr(0, pos);
			std::cout << token << " ";
			hoc.erase(0, pos + delimiter.length());
			cout << hoc << "\n";
		}
		//cout << "\n";
	}
}
/*			What is:
#pragma comment(linker, "/STACK:reserve[,commit]")	???

The /STACK option sets the size of the stack in bytes. Use this option only when you build an .exe file.
The reserve value specifies the total stack allocation in virtual memory. For ARM, x86 and x64 machines, the default stack size is 1 MB.
commit is subject to interpretation by the operating system. In Windows WindowsRT it specifies
the amount of physical memory to allocate at a time.
Committed virtual memory causes space to be reserved in the paging file.
A higher commit value saves time when the application needs more stack space,
but increases the memory requirements and possibly the startup time.
For ARM, x86 and x64 machines, the default commit value is 4 KB.
*/

/*		The "endless loop" cure:
#include<ctime>
int start= clock();
...
while(true)
{
...
if (clock() - start > 800) break;
}
The loop while shall stop after 800 ms!!!!!!!!!!
*/

/*	Print spaces but newline at last!

cout << p[i] << " \n"[i == n];

*/


#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <array>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <ctime>
#include <numeric>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <complex>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <set>
#include <stack>
#include <queue>
#include <utility>
#include <chrono>

using namespace std;

using ll = long long int;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define VPii  vector< pair <int, int> > v(n*n + 1, make_pair(0, 0));
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)

template<class T> inline string tostr(const T & x)
{
	stringstream ss; ss << x; return ss.str();
}
inline ll parse(const string & s)
{
	stringstream ss(s); ll x; ss >> x; return x;
}

template <typename T>
vector<size_t> sort_indexes(const vector<T> &v) {

	// initialize original index locations
	vector<size_t> idx(v.size());
	for (size_t i = 0; i != idx.size(); ++i) idx[i] = i;

	// sort indexes based on comparing values in v
	sort(idx.begin(), idx.end(),
		[&v](size_t i1, size_t i2) {return v[i1] < v[i2]; });

	return idx;
}
int gcd(int n1, int n2) {
	return (n2 == 0) ? n1 : gcd(n2, n1 % n2);
}
int cnt_ones(int i)
{
	i = i - ((i >> 1) & 0x55555555);
	i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
	return (((i + (i >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
}
string DecToBin(int number)
{
	if (number == 0) return "0";
	if (number == 1) return "1";

	if (number % 2 == 0)
		return DecToBin(number / 2) + "0";
	else
		return DecToBin(number / 2) + "1";
}
long long int fact(int a)
{
	long long	int p = 1;
	while (a >= 1)
	{
		p = p*a;
		a--;
	}

	return p;
}

ull cnr(int n, int r)
{
	ull ans = 1;
	r = std::min(r, n - r);

	for (int j = 1; j <= r; j++, n--) {
		// all following do: ans = (ans * n) / j;
		// but the 2 first cases do some simplifications
		// to reduce the possibility of overflow

		if (n % j == 0) {
			ans *= n / j;
		}
		else if (ans % j == 0) {
			ans = (ans / j) * n;
		}
		else {
			ans = (ans * n) / j;
		}
	}
	return ans;
}

template<class T>
inline bool read(T &n)
{
	T x = 0, tmp = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
	if (c == EOF) return false;
	if (c == '-') c = getchar(), tmp = -1;
	while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
	n = x*tmp;
	return true;
}
template <class T>
inline void write(T n)
{
	if (n < 0)
	{
		putchar('-');
		n = -n;
	}
	int len = 0, data[20];
	while (n)
	{
		data[len++] = n % 10;
		n /= 10;
	}
	if (!len) data[len++] = 0;
	while (len--) putchar(data[len] + 48);
}
// generatore di 'lucky numbers' fino a 10e9
vector<ll> lucky;
#define MAX 100000000000ll
void make(ll num) {
	if (MAX < num) return;
	lucky.push_back(num);
	make(num * 10 + 4);
	make(num * 10 + 7);
}
// generatore di primi
bool prime[1000000]{ 1,1 };
void sieve() {
	for (int i = 2; i * i <= 1000000; i++)
		if (!prime[i]) {
			for (int j = i * i; j <= 1000000; j += i) prime[j] = 1;
		}
}
// trova i divisori propri
vector<int> GetDivisors(int number)
{
	vector<int>d;
	for (int i = 1; i <= sqrt(number); i++)
	{
		if (number % i == 0)
		{
			d.push_back(i);
			if (i != (number / i))
			{
				d.push_back(number / i);
			}
		}
	}
	return d;
}
// check divisibility by num of arbitrarily long string representing an integer
bool Is_divisible_by(string s, int num)
{
	int ret = 0;
	for (int i = 0; i < static_cast<int>(s.length()); i++)
		ret = (10 * ret + s[i] - '0') % num;
	return ret == 0;
}
// input a vector of T type with n elems
template<typename T>
vector<T> rv(T n)
{
	vector<T>v(n);
	for (auto &i : v)
		cin >> i;
	return v;
}
int main()
{
	//freopen("C:/input.txt", "r", stdin);
	//freopen("C:/output.txt","w",stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int n, d;
	cin >> n >> d;
	vector<string>from(n), to(n);
	vector<int>t(n);
	set<string>friends;
	for (size_t i = 0; i < n; i++)
		cin >> from[i] >> to[i] >> t[i];
	for (size_t i = 0; i < n; i++)
	{
		for (size_t j = i + 1; j < n; j++)
		{
			if (from[i] == to[j] && to[i] == from[j] && t[j] - t[i]>0 && t[j] - t[i] <= d)
			{
				if (to[i] > from[i])
					swap(to[i], from[i]);
				friends.insert(to[i] + "$" + from[i]);
			}
		}
	}
	cout << friends.size() << "\n";
	for (auto &item : friends)
	{
		string hoc = item;
		string delimiter = "$";
		size_t pos = 0;
		std::string token;
		while ((pos = hoc.find(delimiter)) != std::string::npos) {
			token = hoc.substr(0, pos);
			std::cout << token << " ";
			hoc.erase(0, pos + delimiter.length());
			cout << hoc << "\n";
		}
		//cout << "\n";
	}
}
/*			What is:
#pragma comment(linker, "/STACK:reserve[,commit]")	???

The /STACK option sets the size of the stack in bytes. Use this option only when you build an .exe file.
The reserve value specifies the total stack allocation in virtual memory. For ARM, x86 and x64 machines, the default stack size is 1 MB.
commit is subject to interpretation by the operating system. In Windows WindowsRT it specifies
the amount of physical memory to allocate at a time.
Committed virtual memory causes space to be reserved in the paging file.
A higher commit value saves time when the application needs more stack space,
but increases the memory requirements and possibly the startup time.
For ARM, x86 and x64 machines, the default commit value is 4 KB.
*/

/*		The "endless loop" cure:
#include<ctime>
int start= clock();
...
while(true)
{
...
if (clock() - start > 800) break;
}
The loop while shall stop after 800 ms!!!!!!!!!!
*/

/*	Print spaces but newline at last!

cout << p[i] << " \n"[i == n];

*/


#include<bits/stdc++.h>
using namespace std;

int main(){
    string a,b,ansa[5000],ansb[5000];

    set<string>myset;
    int cnt = 0,d,n,x,f = 0;

    cin >>n >> d;

    map<string, int> data;

    while(n--){
        f = 0;
        cin >> a >> b;
        cin >> x;
        x++;
//        if(myset.count(a+b))
//            continue;
//        cout << data[a+b] << " " << data[b+a]<<endl;
//        if(data[a+b] && data[b+a])
//            continue;
        if(!data[b+a]){
            data[a+b] = x;
        }
        else{
            if(x-data[b+a] <=d && x-data[b+a] > 0){
                for(int k = 0; k < cnt; k++){
                    if(a == ansa[k] && b == ansb[k] || b == ansa[k] && a == ansb[k])
                        f = 1;
                }
                if(!f){
                     ansa[cnt] = a;
                    ansb[cnt] = b;
                    cnt++;

                }
//                cnt++;
//               // cout << a << " " << b << endl;
//                ans+=a;
//                ans+=" ";
//                ans+=b;
//                ans+="\n";
//                myset.insert(a+b);
//                myset.insert(b+a);
            }

        }

    }
    cout << cnt << endl;
    for(int i = 0; i < cnt; i++){
        cout << ansa[i] << " " << ansb[i]<< endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    string a,b,ans;
    int cnt = 0,d,n,x,f = 0;

    cin >>n >> d;

    map<string, int> data;
    ans.clear();

    while(n--){
        cin >> a >> b;
        cin >> x;
        x++;
        if(!data[b+a]){
            data[a+b] = x;
        }
        else{
            if(x-data[b+a] <=d){
                cnt++;

                ans+=a;
                ans+=" ";
                ans+=b;
                ans+="\n";
            }

        }

    }
    cout << cnt << endl;
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    string a,b,ans;

    set<string>myset;
    int cnt = 0,d,n,x,f = 0;

    cin >>n >> d;

    map<string, int> data;
    ans.clear();

    while(n--){
        cin >> a >> b;
        cin >> x;
        x++;
        if(myset.count(a+b))
            continue;
//        cout << data[a+b] << " " << data[b+a]<<endl;
//        if(data[a+b] && data[b+a])
//            continue;
        if(!data[b+a]){
            data[a+b] = x;
        }
        else{
            if(x-data[b+a] <=d && x-data[b+a] > 0){
                cnt++;
                cout << a << " " << b << endl;
                ans+=a;
                ans+=" ";
                ans+=b;
                ans+="\n";
                myset.insert(a+b);
                myset.insert(b+a);
            }

        }

    }
    cout << cnt << endl;
    cout << ans << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n, d,t[1005],cnt = 0,f;
    set<string>myset;
    map<string,int>data;

    string a[1005],b[1005],ansA[1005],ansB[1005];
    cin >> n >> d;

    for (int i = 0; i<n; i++)
        cin >> a[i] >> b[i] >> t[i];
    for (int i = 0; i<n - 1; i++)
        for (int j = i + 1; j<n; j++)
        if ((t[j] - t[i]>0 && t[j] - t[i] <= d) && (a[i] == b[j] && b[i] == a[j])) {

//        if(myset.count(a+b))
//            continue;
////        cout << data[a+b] << " " << data[b+a]<<endl;
////        if(data[a+b] && data[b+a])
////            continue;
//        if(!data[b+a]){
//            data[a+b] = x;
//        }

        f = 0;
        for (int k = 0; k < cnt; k++)
            if (a[i] == ansA[k] && b[i] == ansB[k] || a[i] == ansB[k] && b[i] == ansA[k]) {
                    f = 1;
                    break;
            }
            if (!f) {
                ansA[cnt] = a[i];
                ansB[cnt] = b[i];
                cnt++;
            }
        }
    cout << cnt << endl;
    for (int i = 0; i < cnt; i++)cout << ansA[i] << " " <<ansB[i] << endl;

}


#include<bits/stdc++.h>
using namespace std;

int main(){
    string a,b,ans;

    set<string>myset;
    int cnt = 0,d,n,x,f = 0;

    cin >>n >> d;

    map<string, int> data;
    ans.clear();

    while(n--){
        cin >> a >> b;
        cin >> x;
        x++;
        if(myset.count(a+b))
            continue;
//        cout << data[a+b] << " " << data[b+a]<<endl;
//        if(data[a+b] && data[b+a])
//            continue;
        if(!data[b+a]){
            data[a+b] = x;
        }
        else{
            if(x-data[b+a] <=d && x-data[b+a] > 0){
                cnt++;
               // cout << a << " " << b << endl;
                ans+=a;
                ans+=" ";
                ans+=b;
                ans+="\n";
                myset.insert(a+b);
                myset.insert(b+a);
            }

        }

    }
    cout << cnt << endl;
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    string a,b,ans;
    int cnt = 0,d,n,x,f = 0;

    cin >>n >> d;

    map<string, int> data;
    ans.clear();

    while(n--){
        cin >> a >> b;
        cin >> x;
        x++;
        if(!data[b+a]){
            data[a+b] = x;
        }
        else{
            if(x-data[b+a] <=d && x-data[b+a] > 0){
                cnt++;

                ans+=a;
                ans+=" ";
                ans+=b;
                ans+="\n";
            }

        }

    }
    cout << cnt << endl;
    cout << ans << endl;
}


/**
* DID YOU GET WHAT YOU WANTED FROM THIS LIFE?
* I DID....
* AND WHAT DID YOU WANT?
* TO CALL MYSELF BELOVED.
* TO FEEL MYSELF BELOVED ON THE EARTH....
*/
#include <bits/stdc++.h>
#define sz(x) (x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define ___WTHIT___ main
//#include <boost/accumulators/accumulators.hpp>
//#include <dirent.h>
//#include <stdio.h>
//#pragma comment(linker, "/STACK:16777216")
//#define M 300002
//#define pi 3.14159265358979323846
#define MINF -2000000000
//#define M  100005
#define K 28
using namespace std;
typedef long long ll;
//typedef long long ull;
const ll INF = 1.e18 + 2;
const ll mod = 1000006;
const int MAXN = 100005;
using namespace std;
string a, b; int t;
struct item {
    string a, b;
    item(string a, string b) : a(a), b(b) { }
    bool operator < (const item & rhs) const {
        return rhs.a < this->a || (rhs.a == this->a && rhs.b < this->b);
    }
};
map <pair<string, string>, int> M, MS;
vector <pair <string, string>> ans;
int main() {
    ios_base::sync_with_stdio(0);
    //
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, d, res = 0; cin >> n >> d;
    for(int i = 0; i < n; ++i) {
            cin >> a >> b >> t;
            pair<string, string> tempitem = {b, a}, tempitem_ = {a, b};

            if(!MS[tempitem]) {
                MS[tempitem_] |= 1;
                M[tempitem_] = t;
            }

            else if(fabs(M[tempitem] - t) <= d && fabs(M[tempitem] - t) > 0) ans.push_back({a, b});

    }
    cout << ans.size() << endl;
    for(auto it : ans) {
        cout << it.first << " " << it.second << endl;
    }
}


/**
* DID YOU GET WHAT YOU WANTED FROM THIS LIFE?
* I DID....
* AND WHAT DID YOU WANT?
* TO CALL MYSELF BELOVED.
* TO FEEL MYSELF BELOVED ON THE EARTH....
*/
#include <bits/stdc++.h>
#define sz(x) (x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define ___WTHIT___ main
//#include <boost/accumulators/accumulators.hpp>
//#include <dirent.h>
//#include <stdio.h>
//#pragma comment(linker, "/STACK:16777216")
//#define M 300002
//#define pi 3.14159265358979323846
#define MINF -2000000000
//#define M  100005
#define K 28
using namespace std;
typedef long long ll;
//typedef long long ull;
const ll INF = 1.e18 + 2;
const ll mod = 1000006;
const int MAXN = 100005;
using namespace std;
string a, b; int t;
struct item {
    string a, b;
    item(string a, string b) : a(a), b(b) { }
    bool operator < (const item & rhs) const {
        return rhs.a < this->a || (rhs.a == this->a && rhs.b < this->b);
    }
};
map <pair<string, string>, int> M, MS, L;
vector <pair <string, string>> ans;
int main() {
    ios_base::sync_with_stdio(0);
    //
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, d, res = 0; cin >> n >> d;
    for(int i = 0; i < n; ++i) {
            cin >> a >> b >> t;
            if(L[{a, b}]) continue;
            pair<string, string> tempitem = {b, a}, tempitem_ = {a, b};
            if(!MS[tempitem]) {
                MS[tempitem_] |= 1;
                M[tempitem_] = t;
            }
            else if(fabs(M[tempitem] - t) <= d && fabs(M[tempitem] - t) > 0) ans.push_back({a, b}), L[{a, b}] = L[{b, a}] |= 1;

    }
    cout << ans.size() << endl;
    for(auto it : ans) {
        cout << it.first << " " << it.second << endl;
    }
}


/**
* DID YOU GET WHAT YOU WANTED FROM THIS LIFE?
* I DID....
* AND WHAT DID YOU WANT?
* TO CALL MYSELF BELOVED.
* TO FEEL MYSELF BELOVED ON THE EARTH....
*/
#include <bits/stdc++.h>
#define sz(x) (x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define ___WTHIT___ main
//#include <boost/accumulators/accumulators.hpp>
//#include <dirent.h>
//#include <stdio.h>
//#pragma comment(linker, "/STACK:16777216")
//#define M 300002
//#define pi 3.14159265358979323846
#define MINF -2000000000
//#define M  100005
#define K 28
using namespace std;
typedef long long ll;
//typedef long long ull;
const ll INF = 1.e18 + 2;
const ll mod = 1000006;
const int MAXN = 100005;
using namespace std;
string a, b; int t;
struct item {
    string a, b;
    int time;
    item(string a, string b, int time) : a(a), b(b), time(time) { }
    bool operator < (const item & rhs) const {
        return rhs.a < this->a || (rhs.a == this->a && rhs.b < this->b);
    }
};
map <item, int> M;
vector <pair <string, string>> ans;
int main() {
    ios_base::sync_with_stdio(0);
    //
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, d, res = 0; cin >> n >> d;
    for(int i = 0; i < n; ++i) {
            cin >> a >> b >> t;
            item tempitem = item(b, a, t), tempitem_ = item(a, b, t);
            if(!M[tempitem]) M[tempitem_] = t;
            else {
                if(fabs(M[tempitem] - t) <= d) ans.push_back({a, b});
            }
    }
    cout << ans.size() << endl;
    for(auto it : ans) {
        cout << it.first << " " << it.second << endl;
    }
}


/**
* DID YOU GET WHAT YOU WANTED FROM THIS LIFE?
* I DID....
* AND WHAT DID YOU WANT?
* TO CALL MYSELF BELOVED.
* TO FEEL MYSELF BELOVED ON THE EARTH....
*/
#include <bits/stdc++.h>
#define sz(x) (x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define ___WTHIT___ main
//#include <boost/accumulators/accumulators.hpp>
//#include <dirent.h>
//#include <stdio.h>
//#pragma comment(linker, "/STACK:16777216")
//#define M 300002
//#define pi 3.14159265358979323846
#define MINF -2000000000
//#define M  100005
#define K 28
using namespace std;
typedef long long ll;
//typedef long long ull;
const ll INF = 1.e18 + 2;
const ll mod = 1000006;
const int MAXN = 100005;
using namespace std;
string a, b; int t[1005];
struct item {
    string a, b;
    item(string a, string b) : a(a), b(b) { }
    bool operator < (const item & rhs) const {
        return rhs.a < this->a || (rhs.a == this->a && rhs.b < this->b);
    }
};
map <pair<string, string>, int> M;
vector <pair <string, string>> ans, da(1005);
int main() {
    ios_base::sync_with_stdio(0);
    //
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, d, res = 0; cin >> n >> d;
    for(int i = 0; i < n; ++i) {
        cin >> da[i].first >> da[i].second >> t[i];
    }
    for(int i = 0; i < n; ++i) for(int j = i + 1; j < n; ++j) {
        if(da[i].first == da[j].second && da[j].first == da[i].second &&
           fabs(t[i] - t[j]) <= d && fabs(t[i] - t[j]) > 0 && !M[{da[i].first, da[i].second}]) {
            ans.push_back({da[i].first, da[i].second});
            M[{da[i].first, da[i].second}] = M[{da[i].second, da[i].first}] |= 1;
           }
    }
    cout << ans.size() << endl;
    for(auto it : ans) {
        cout << it.first << " " << it.second << endl;
    }
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>pll;
typedef vector<ll>vll;
typedef set<ll>sll;

const ll MAXN = ll(5e6);
const ll INF = ll(1e17);
const ld EPS = ll(1e-9);
const ll MOD = ll(1e9) + 7;
const ll MILLION = ll(1e6);
const ll BILLION = ll(1e9);

ll n, d;
string a[MAXN / 100], b[MAXN / 100];
ll t[MAXN / 100];
map<pair<string, string>, ll>u;
vector<pair<string, string> >prr;

int main(){

    cin >> n >> d;
    for(ll i = 1; i <= n; ++i){
        cin >> a[i] >> b[i] >> t[i];
    }
    for(ll i = 1; i <= n; ++i){
        for(ll j = i + 1; j <= n; ++j){
            if(a[j] == b[i] && b[j] == a[i] && t[j] - t[i] <= d && t[j] - t[i] > 0 && !u[make_pair(a[i], b[i])]){
                u[make_pair(a[i], b[i])] = 1;
                u[make_pair(b[i], a[i])] = 1;
                prr.push_back(make_pair(a[i], b[i]));
            }
        }
    }
    cout << (ll)prr.size() << "\n";
    for(auto i : prr){
        cout << i.first << " " << i.second << "\n";
    }

    return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>pll;
typedef vector<ll>vll;
typedef set<ll>sll;

const ll MAXN = ll(5e6);
const ll INF = ll(1e17);
const ld EPS = ll(1e-9);
const ll MOD = ll(1e9) + 7;
const ll MILLION = ll(1e6);
const ll BILLION = ll(1e9);

ll n, d;
string a[MAXN / 100], b[MAXN / 100];
ll t[MAXN / 100];
map<pair<string, string>, ll>u;
vector<pair<string, string> >prr;

int main(){

    cin >> n >> d;
    for(ll i = 1; i <= n; ++i){
        cin >> a[i] >> b[i] >> t[i];
    }
    for(ll i = 1; i <= n; ++i){
        for(ll j = i + 1; j <= n; ++j){
            if(a[j] == b[i] && b[j] == a[i] && t[j] - t[i] <= d && !u[make_pair(a[i], b[i])]){
                u[make_pair(a[i], b[i])] = 1;
                u[make_pair(b[i], a[i])] = 1;
                prr.push_back(make_pair(a[i], b[i]));
            }
        }
    }
    cout << (ll)prr.size() << "\n";
    for(auto i : prr){
        cout << i.first << " " << i.second << "\n";
    }

    return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>pll;
typedef vector<ll>vll;
typedef set<ll>sll;

const ll MAXN = ll(5e6);
const ll INF = ll(1e17);
const ld EPS = ll(1e-9);
const ll MOD = ll(1e9) + 7;
const ll MILLION = ll(1e6);
const ll BILLION = ll(1e9);

ll n, d;
string a[MAXN / 100], b[MAXN / 100];
ll t[MAXN / 100];
map<pair<string, string>, ll>u;
vector<pair<string, string> >prr;

int main(){

    cin >> n >> d;
    for(ll i = 1; i <= n; ++i){
        cin >> a[i] >> b[i] >> t[i];
    }
    for(ll i = 1; i <= n; ++i){
        for(ll j = i + 1; j <= n; ++j){
            if(a[j] == b[i] && b[j] == a[i] && abs(t[i] - t[j]) <= d && !u[make_pair(a[i], b[i])]){
                u[make_pair(a[i], b[i])] = 1;
                u[make_pair(b[i], a[i])] = 1;
                prr.push_back(make_pair(a[i], b[i]));
            }
        }
    }
    cout << (ll)prr.size() << "\n";
    for(auto i : prr){
        cout << i.first << " " << i.second << "\n";
    }

    return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>pll;
typedef vector<ll>vll;
typedef set<ll>sll;

const ll MAXN = ll(5e6);
const ll INF = ll(1e17);
const ld EPS = ll(1e-9);
const ll MOD = ll(1e9) + 7;
const ll MILLION = ll(1e6);
const ll BILLION = ll(1e9);

ll n, d;
string a[MAXN], b[MAXN];
ll t[MAXN];
map<pair<string, string>, ll>u;
vector<pair<string, string> >prr;

int main(){

    cin >> n >> d;
    for(ll i = 1; i <= n; ++i){
        cin >> a[i] >> b[i] >> t[i];
    }
    for(ll i = 1; i <= n; ++i){
        for(ll j = i + 1; j <= n; ++j){
            if(a[j] == b[i] && b[j] == a[i] && abs(t[i] - t[j]) <= d && !u[make_pair(a[i], b[i])]){
                u[make_pair(a[i], b[i])] = 1;
                u[make_pair(b[i], a[i])] = 1;
                prr.push_back(make_pair(a[i], b[i]));
            }
        }
    }
    cout << (ll)prr.size() << "\n";
    for(auto i : prr){
        cout << i.first << " " << i.second << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
  map< string , pair<string, int > > m;
  set< pair<string,string> > ans;
  int n,d; cin >> n >> d;
  for(int i = 0 ;i < n ; ++i)
    {
      int c;
      string a, b; cin >> a >> b >> c;
      if(m.count(b) != 0)
	{
	  if(c-m[b].second <= d and c-m[b].second > 0)
	    {
	      if(ans.find({b,a}) == ans.end() and ans.find({a,b}) == ans.end() )
		ans.insert({a,b});
	    }
	}
      m[a] = {b,c};
    }
  cout << ans.size() << "\n";
  for(auto it = ans.begin(); it != ans.end() ; it++)
    {
      cout << it->first << " " << it->second << "\n";
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
  map< pair<string,string> , vector<int> > m;
  set< pair<string,string> > ans;
  int n,d; cin >> n >> d;
  for(int i = 0 ;i < n ; ++i)
    {
      int c;
      string a, b; cin >> a >> b >> c;
      m[{a,b}].push_back(c);
      if(m.count({b,a}) != 0)
  	{
	  for(int i = 0 ; i < m[{b,a}].size() ; ++i)
	    {
	      int it = m[{b,a}][i];
	      if(c-it <= d and c-it > 0)
		{
		  if(ans.find({b,a}) == ans.end() and ans.find({a,b}) == ans.end() )
		    {
		      ans.insert({a,b});
		      break;
		    }
		}
	    }
  	}
    }
  cout << ans.size() << "\n";
  for(auto it = ans.begin(); it != ans.end() ; it++)
    {
      cout << it->first << " " << it->second << "\n";
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
  map< pair<string,string> , set<int> > m;
  set< pair<string,string> > ans;
  int n,d; cin >> n >> d;
  for(int i = 0 ;i < n ; ++i)
    {
      int c;
      string a, b; cin >> a >> b >> c;
      m[{a,b}].insert(c);
      if(m.count({b,a}) != 0)
  	{
	  for(auto it = m[{b,a}].end() ; it != m[{b,a}].begin() ; it--)
	    {
	      // cout << (*it) << "\n";
	      if(c-(*it) <= d and c-(*it) > 0)
		{
		  if(ans.find({b,a}) == ans.end() and ans.find({a,b}) == ans.end() )
		    {
		      ans.insert({a,b});
		      break;
		    }
		}
	    }
  	}
    }
  cout << ans.size() << "\n";
  for(auto it = ans.begin(); it != ans.end() ; it++)
    {
      cout << it->first << " " << it->second << "\n";
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
  map< pair<string,string> , int > m;
  set< pair<string,string> > ans;
  int n,d; cin >> n >> d;
  for(int i = 0 ;i < n ; ++i)
    {
      int c;
      string a, b; cin >> a >> b >> c;
      m[{a,b}] = c;
      if(m.count({b,a}) != 0)
  	{
  	  if(c-m[{b,a}] <= d and c-m[{b,a}] > 0)
  	    {
  	      if(ans.find({b,a}) == ans.end() and ans.find({a,b}) == ans.end() )
  		ans.insert({a,b});
  	    }
  	}
    }
  cout << ans.size() << "\n";
  for(auto it = ans.begin(); it != ans.end() ; it++)
    {
      cout << it->first << " " << it->second << "\n";
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
  map< string , pair<string, int > > m;
  set< pair<string,string> > ans;
  int n,d; cin >> n >> d;
  for(int i = 0 ;i < n ; ++i)
    {
      int c;
      string a, b; cin >> a >> b >> c;
      if(m.count(b) != 0)
	{
	  if(c-m[b].second <= d)
	    {
	      if(ans.find({b,a}) == ans.end() and ans.find({a,b}) == ans.end() )
		ans.insert({a,b});
	    }
	}
      m[a] = {b,c};
    }
  cout << ans.size() << "\n";
  for(auto it = ans.begin(); it != ans.end() ; it++)
    {
      cout << it->first << " " << it->second << "\n";
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
  map< pair<string,string> , int > m;
  set< pair<string,string> > ans;
  int n,d; cin >> n >> d;
  for(int i = 0 ;i < n ; ++i)
    {
      int c;
      string a, b; cin >> a >> b >> c;
      if(m.count({b,a}) != 0)
  	{
  	  if(c-m[{b,a}] <= d and c-m[{b,a}] > 0)
  	    {
  	      if(ans.find({b,a}) == ans.end() and ans.find({a,b}) == ans.end() )
  		ans.insert({a,b});
  	    }
  	}
      m[{a,b}] = c;
    }
  cout << ans.size() << "\n";
  for(auto it = ans.begin(); it != ans.end() ; it++)
    {
      cout << it->first << " " << it->second << "\n";
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, d;
    vector<string> v1;
    vector<string> v2;
    vector<int> v3;
    vector<int> v4;
    string s1, s2;
    set<pair<string, string> > s;
    int p;
    scanf("%d %d", &n, &d);
    for(int i = 0; i < n; i++){
        cin >> s1 >> s2 >> p;
        v1.push_back(s1);
        v2.push_back(s2);
        v3.push_back(p);
    }
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n ;j++){
            if(v2[j]==v1[i] && v1[j] == v2[i] && abs(v3[j]-v3[i]) <= d && v3[j]-v3[i] > 0){
                s.insert(make_pair(min(v1[i], v2[i]), max(v1[i],v2[i])));
            }
            if(v3[j]-v3[i]>d)
                break;
        }
    }
    int sz = s.size();
    printf("%d\n", sz);
    set<pair<string, string> >::iterator it;
    for(it = s.begin(); it != s.end(); it++){
        cout << (*it).first << " " << (*it).second << endl;
    }
}

   	 		  		 	 	 			  		 	     	//hellobig_tq


#include <bits/stdc++.h>

#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <math.h>

///Kurbanbayev Zhan <Never Give Up>

#define ll long long
#define uns unsigned
#define rt return
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define itr ::iterator
#define F first
#define S second
#define sz(x) (int)x.size()
#define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define FOR(x,n,i) for (int i=x;i<=n;++i)
#define sf scanf
#define pf printf
#define fpi freopen
#define fpo freopen
#define PI 3.14159265358979323846264338327950288419716939937510
#define dis(x1,y1,x2,y2) sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
const int INF=(int)1e9+7;
const int MX=(int)1e6+17;

using namespace std;

    int n,d,x;
    string a,b;
    map <pair<string,string>,int> m;
    vector < pair <string,string> > ans;
int main()
{
    cin>>n>>d;

    for (int i=1;i<=n;i++)
    {
        cin>>a>>b>>x;
        m[mp(a,b)]=x;
    }

    if (sz(m)<=1) {cout<<-0;rt 0;}

    forit(i,m)
    {
        map <pair<string,string>,int>itr it=i;
        it++;
        if (i->F.F==it->F.S&&i->F.S==it->F.F&&abs(i->S-it->S)<=d) ans.pb(mp(i->F.F,i->F.S));
    }

 //   if (!sz(ans)) {cout<<0;rt 0;}

    cout<<sz(ans)<<endl;

    for (int i=0;i<sz(ans);i++)
    {
        cout<<ans[i].F<<' '<<ans[i].S<<endl;
    }

    rt 0;
}


#include <bits/stdc++.h>

#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <math.h>

///Kurbanbayev Zhan <Never Give Up>

#define ll long long
#define uns unsigned
#define rt return
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define itr ::iterator
#define F first
#define S second
#define sz(x) (int)x.size()
#define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define FOR(x,n,i) for (int i=x;i<=n;++i)
#define sf scanf
#define pf printf
#define fpi freopen
#define fpo freopen
#define PI 3.14159265358979323846264338327950288419716939937510
#define dis(x1,y1,x2,y2) sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
const int INF=(int)1e9+7;
const int MX=(int)1e6+17;

using namespace std;

    int n,d,x[MX];
    string a[MX],b[MX];
    map <pair<string,string>,bool> used;
    vector <pair<string,string> > ans;
int main()
{
    cin>>n>>d;
    for (int i=1;i<=n;i++) cin>>a[i]>>b[i]>>x[i];

    for (int i=1;i<=n;i++)
    {
        for (int j=i+1;j<=n;j++)
        {
            if (a[i]==b[j]&&b[i]==a[j]&&abs(x[i]-x[j])<=d&&abs(x[i]-x[j])>=0&&!used[mp(a[i],b[i])])
            {
                used[mp(a[i],b[i])]=1;
                used[mp(b[i],a[i])]=1;
                ans.pb(mp(a[i],b[i]));
            }
        }
    }

    cout<<sz(ans)<<endl;

    for (int i=0;i<sz(ans);i++) cout<<ans[i].F<<' '<<ans[i].S<<endl;

    rt 0;
}


#include <bits/stdc++.h>

#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <math.h>

///Kurbanbayev Zhan <Never Give Up>

#define ll long long
#define uns unsigned
#define rt return
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define itr ::iterator
#define F first
#define S second
#define sz(x) (int)x.size()
#define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define FOR(x,n,i) for (int i=x;i<=n;++i)
#define sf scanf
#define pf printf
#define fpi freopen
#define fpo freopen
#define PI 3.14159265358979323846264338327950288419716939937510
#define dis(x1,y1,x2,y2) sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
const int INF=(int)1e9+7;
const int MX=(int)1e6+17;

using namespace std;

    int n,d,x[MX];
    string a[MX],b[MX];
    map <pair<string,string>,bool> used;
    vector <pair<string,string> > ans;
int main()
{
    cin>>n>>d;
    for (int i=1;i<=n;i++) cin>>a[i]>>b[i]>>x[i];

    for (int i=1;i<=n;i++)
    {
        for (int j=i+1;j<=n;j++)
        {
            if (a[i]==b[j]&&b[i]==a[j]&&abs(x[i]-x[j])<=d&&abs(x[i]-x[j])>0&&!used[mp(a[i],b[i])])
            {
                used[mp(a[i],b[i])]=1;
                used[mp(b[i],a[i])]=1;
                ans.pb(mp(a[i],b[i]));
            }
        }
    }

    cout<<sz(ans)<<endl;

    for (int i=0;i<sz(ans);i++) cout<<ans[i].F<<' '<<ans[i].S<<endl;

    rt 0;
}


#include <bits/stdc++.h>

#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <math.h>

///Kurbanbayev Zhan <Never Give Up>

#define ll long long
#define uns unsigned
#define rt return
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define itr ::iterator
#define F first
#define S second
#define sz(x) (int)x.size()
#define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define FOR(x,n,i) for (int i=x;i<=n;++i)
#define sf scanf
#define pf printf
#define fpi freopen
#define fpo freopen
#define PI 3.14159265358979323846264338327950288419716939937510
#define dis(x1,y1,x2,y2) sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
const int INF=(int)1e9+7;
const int MX=(int)1e6+17;

using namespace std;

    int n,d,x;
    string a,b;
    map <pair<string,string>,int> m;
    vector < pair <string,string> > ans;
int main()
{
    cin>>n>>d;

    for (int i=1;i<=n;i++)
    {
        cin>>a>>b>>x;
        m[mp(a,b)]=x;
    }

    if (sz(m)<=1) {cout<<-0;rt 0;}

    forit(i,m)
    {
        map <pair<string,string>,int>itr it=i;
        it++;
        if (it==m.end()) break;
        if (i->F.F==it->F.S&&i->F.S==it->F.F&&abs(i->S-it->S)<=d&&abs(i->S-it->S)>0) ans.pb(mp(i->F.F,i->F.S));
    }

 //   if (!sz(ans)) {cout<<0;rt 0;}

    cout<<sz(ans)<<endl;

    for (int i=0;i<sz(ans);i++)
    {
        cout<<ans[i].F<<' '<<ans[i].S<<endl;
    }

    rt 0;
}


n = int(input())
diff = 0
risp = []
for i in range(n):
    x, y = map(int, input().split())
    if abs(diff + x) < 501:
        diff += x
        risp.append('A')
    else:
        diff -= y
        risp.append('G')

if abs(diff) < 501:
    print(''.join(risp))
else:
    print('-1')


from sys import stdin
n=int(stdin.readline())
diff = 0
risp = []
for _ in range(n):
    x, y = map(int, stdin.readline().split())
    if abs(diff + x) < 501:
        diff += x
        risp.append('A')
    else:
        diff -= y
        risp.append('G')

if abs(diff) < 501:
    print(''.join(risp))
else:
    print('-1')


n = int(input())
a = 0
g = 0
risp = ''
eggs = [list(map(int, input().split())) for i in range(n)]
for elem in eggs:
    if abs(a + elem[0] - g) < abs(a - g - elem[1]):
        a += elem[0]
        risp += 'A'
    else:
        g += elem[1]
        risp += 'G'

if abs(a - g) <= 500:
    print(risp)
else:
    print('-1')


n = int(input())
a = 0
g = 0
risp = ''
for i in range(n):
    x,y = input().split()
    x = int(x)
    y = int(y)
    if abs(a + x - g) < abs(a - g - y):
        a += x
        risp += 'A'
    else:
        g += y
        risp += 'G'

if abs(a - g) <= 500:
    print(risp)
else:
    print('-1')


n = int(input())
diff = 0
risp = []
for i in range(n):
    x,y = input().split()
    x = int(x)
    y = int(y)
    if abs(diff + x) < abs(diff - y):
        diff += x
        risp.append('A')
    else:
        diff -= y
        risp.append('G')

if abs(diff) <= 500:
    print(''.join(risp))
else:
    print('-1')


n = int(input())
a = 0
g = 0
risp = ''
eggs = [list(map(int, input().split())) for i in range(n)]
eggs = sorted(eggs, key= lambda elem : abs(elem[0]-elem[1]))
for elem in eggs:
    if abs(a + elem[0] - g) < abs(a - g - elem[1]):
        a += elem[0]
        risp += 'A'
    else:
        g += elem[1]
        risp += 'G'

if abs(a - g) <= 500:
    print(risp)
else:
    print('-1')


def arr_2d(n):
    return [[int(x) for x in stdin.readline().split()] for i in range(n)]

def get_col(arr, i):
    return [row[i] for row in arr]

from sys import stdin

def main():
    n = int(input())
    a = arr_2d(n)
    sa, sb, ans = 0, 0, ''
    for i, j in a:
        if abs((sa + i) - sb) <= abs((sb + j) - sa):
            ans += 'A'
            sa += i
        else:
            ans += 'G'
            sb += j

    print(ans if abs(sa - sb) <= 500 else -1)

if __name__ == '__main__':
    main()


def arr_2d(n):
    return [[float(x) for x in stdin.readline().split()] for i in range(n)]

def get_col(arr, i):
    return [row[i] for row in arr]

from sys import stdin

def main():
    n = int(input())
    a = arr_2d(n)
    sa, sb, ans = 0, 0, ''
    for i, j in a:
        if abs((sa + i) - sb) <= abs((sb + j) - sa):
            ans += 'A'
            sa += i
        else:
            ans += 'G'
            sb += j

    print(ans if abs(sa - sb) <= 500 else -1)

if __name__ == '__main__':
    main()


def arr_2d(n):
    return [[int(x) for x in stdin.readline().split()] for i in range(n)]

def get_col(arr, i):
    return [row[i] for row in arr]

from sys import stdin

def main():
    n = int(input())
    a = arr_2d(n)
    sa, sb, ans = sum(get_col(a, 0)), sum(get_col(a, 1)), ''
    for i, j in a:
        if sa >= sb:
            sa -= i
            ans += 'G'
        else:
            sb -= j
            ans += 'A'

    print(ans if abs(sa - sb) <= 500 else -1)

if __name__ == '__main__':
    main()


def arr_2d(n):
    return [[int(x) for x in stdin.readline().split()] for i in range(n)]

def get_col(arr, i):
    return [row[i] for row in arr]

from sys import stdin

def main():
    n = int(input())
    a = arr_2d(n)
    sa, sb, ans = sum(get_col(a, 0)), sum(get_col(a, 1)), ''
    for i, j in a:
        if sa >= sb:
            sa -= i
            ans += 'A'
        else:
            sb -= j
            ans += 'G'

    print(ans if abs(sa - sb) <= 500 else -1)

if __name__ == '__main__':
    main()


def arr_2d(n):
    return [[float(x) for x in stdin.readline().split()] for i in range(n)]

def get_col(arr, i):
    return [row[i] for row in arr]

from sys import stdin

def main():
    n = int(input())
    a = arr_2d(n)
    sa, sb, ans = 0, 0, []
    for i, j in a:
        if abs((sa + i) - sb) <= abs((sb + j) - sa):
            ans.append('A')
            sa += i
        else:
            ans.append('G')
            sb += j

    print(''.join(ans) if abs(sa - sb) <= 500 else -1)

if __name__ == '__main__':
    main()


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        import os
        self.os = os
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            self.os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

import time
start_time = time.time()

import collections as col
import math, string
from functools import reduce

def getInts():
    return [int(s) for s in input().split()]

def getInt():
    return int(input())

def getStrs():
    return [s for s in input().split()]

def getStr():
    return input()

def listStr():
    return list(input())

"""
Greedily try to keep the difference <= 500 at all times?
Suggest A leads G by D, and the current prices are x, 1000-x
If D+x > 500, what does that tell us about D-(1000-x)? That it is > -500
So it's always possible.
If D+x <= 500, just keep rolling with that
"""

def solve():
    N = getInt()
    ans = []
    diff = 0 # A-G
    for n in range(N):
        a, g = getInts()
        if diff:
            if diff+a <= 500:
                ans.append('A')
                diff += a
            else:
                ans.append('G')
                diff -= g
        else:
            if diff-g >= -500:
                ans.append('G')
                diff -= g
            else:
                ans.append('A')
                diff += a
    return ''.join(ans)

#for _ in range(getInt()):
print(solve())


"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by adi0311(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
import heapq
from math import *
from collections import defaultdict as dd  # defaultdict(<datatype>) Free of KeyError.
from collections import deque  # deque(list) append(), appendleft(), pop(), popleft() - O(1)
from collections import Counter as c  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(var)
def l(): return list(map(int, data().split()))
def sl(): return list(map(str, data().split()))
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [[val for i in range(n)] for j in range(m)]

n = int(data())
a, g = sp()
s = list()
if a <= g:
    s.append("A")
    sa, sg = a, 0
else:
    s.append("G")
    sa, sg = 0, g
for i in range(n-1):
    newa, newg = sp()
    if sg+newg-sa <= 500:
        sg +=newg
        s.append("G")
    elif sa+newa-sg <= 500:
        sa += newa
        s.append("A")
    else:
        if sg+newg-sa < sa+newa-sg:
            sg += newg
            s.append("G")
        else:
            sa += newa
            s.append("A")
if abs(sa-sg) > 500:
    out("-1")
    exit()
for i in range(n):
    out(str(s[i]))
exit()


"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by adi0311(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
import heapq
from math import *
from collections import defaultdict as dd  # defaultdict(<datatype>) Free of KeyError.
from collections import deque  # deque(list) append(), appendleft(), pop(), popleft() - O(1)
from collections import Counter as c  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(var)
def l(): return list(map(int, data().split()))
def sl(): return list(map(str, data().split()))
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [[val for i in range(n)] for j in range(m)]

n = int(data())
a, g = sp()
if n == 1 and abs(a-g) > 500:
    out("-1")
    exit()
s = "A"
sa, sg = a, 0
for i in range(n-1):
    newa, newg = sp()
    if sg+newg-sa <= 500:
        sg +=newg
        s += "G"
    elif sa+newa-sg <= 500:
        sa += newa
        s += "A"
    else:
        if sg+newg-sa < sa+newa-sg:
            sg += newg
            s += "G"
        else:
            sa += newa
            s += "A"
if abs(sa-sg) > 500:
    out("-1")
    exit()
out(s)


"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by adi0311(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
import heapq
from math import *
from collections import defaultdict as dd  # defaultdict(<datatype>) Free of KeyError.
from collections import deque  # deque(list) append(), appendleft(), pop(), popleft() - O(1)
from collections import Counter as c  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(var)
def l(): return list(map(int, data().split()))
def sl(): return list(map(str, data().split()))
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [[val for i in range(n)] for j in range(m)]

n = int(data())
a, g = sp()
if a <= g:
    s = "A"
    sa, sg = a, 0
else:
    s = "G"
    sa, sg = 0, g
for i in range(n-1):
    newa, newg = sp()
    if sg+newg-sa <= 500:
        sg +=newg
        s += "G"
    elif sa+newa-sg <= 500:
        sa += newa
        s += "A"
    else:
        if sg+newg-sa < sa+newa-sg:
            sg += newg
            s += "G"
        else:
            sa += newa
            s += "A"
if abs(sa-sg) > 500:
    out("-1")
    exit()
out(s)


n=int(input())
r=''
x,y=0,0
l=[]
for i in range(n):
    l.append(sorted(list(map(int,input().split()))))
l.sort(reverse=True)
for i in range(n):
    if(x<=y):
        x+=min(l[i])
        r+='A'
    else:
        r+='G'
if(abs(x-y)<=500):
    print(r)
else:
    print("Impossible")


n=int(input())
r=''
x,y=0,0
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
for i in range(n):
    if(abs(x+l[i][0]-y)<=500):
        r+='A'
        x+=l[i][0]
    else:
        y+=l[i][1]
        r+='G'
if(abs(x-y)<=500):
    print(r)
else:
    print(-1)


n=int(input())
r=[]
x,y=0,0
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
for i in range(n):
    if(abs(x+l[i][0]-y)<=500):
        r.append('A')
        x+=l[i][0]
    else:
        y+=l[i][1]
        r.append('G')
if(abs(x-y)<=500):
    print(''.join(r))
else:
    print(-1)


from sys import *
input=stdin.readline
n=int(input())
r=[]
x,y=0,0
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
for i in range(n):
    if(abs(x+l[i][0]-y)<=500):
        r.append('A')
        x+=l[i][0]
    else:
        y+=l[i][1]
        r.append('G')
if(abs(x-y)<=500):
    print(''.join(r))
else:
    print(-1)


n = int(input())
s = []
sv = 0
sg = 0
for i in range(n):
    f = 0
    a,g = list(map(int,input().split()))
    if a<=g:
        s.append('A')
        sv += a
        f = 1
    else:
        s.append('G')
        sg += g
    diff = abs(sv-sg)
    if diff>500:
        if f==1:
            sv-=a
            sg+=g
            _ = s.pop()
            s.append('G')
        else:
            sg-=g
            sv+=a
            _ = s.pop()
            s.append('A')
        diff = abs(sv - sg)
print(''.join(s))


import os,io
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n = int(input())
s = []
sv = 0
sg = 0
for i in range(n):
    f = 0
    a,g = list(map(int,input().split()))
    if a<=g:
        s.append('A')
        sv += a
        f = 1
    else:
        s.append('G')
        sg += g
    diff = abs(sv-sg)
    if diff>500:
        if f==1:
            sv-=a
            sg+=g
            _ = s.pop()
            s.append('G')
        else:
            sg-=g
            sv+=a
            _ = s.pop()
            s.append('A')
        diff = abs(sv - sg)
if diff>500:
    print(-1)
print(''.join(s))


import sys
input = sys.stdin.buffer.readline
from math import ceil
def I(): return(list(map(int,input().split())))
def sieve(n):
	a=[1]*n
	for i in range(2,n):
	    if a[i]:
	        for j in range(i*i,n,i):
	            a[j]=0
	return a
a = []
b = []

for __ in range(int(input())):
	a1,b1 = I()
	a.append(a1)
	b.append(b1)
x = sum(a)
t1 = ceil((x-500)/1000)
t2 = (x+500)//1000
n = len(a)
if t1<=n:
	print("G"*t1+"A"*(n-t1))
elif t2>=0:
	print("G"*t2+A*(n-t2))
else:
	print(-1)


sum = 0
s = ''
n = int(input())
for _ in range(n):
    a,g = map(int,input().split())
    if sum+a <= 500:
        sum+=a
        s+='A'
    else:
        sum-=g
        s += 'G'
print(s)


sum = 0
for _ in range(int(input())):
    a,g = map(int,input().split())
    if sum+a <= 500:
        sum+=a
        print('A',end='')
    else:
        sum-=g
        print('G',end='')


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys

mod = 10 ** 9 + 7
mod1 = 998244353
# setrecursionlimit(300000)
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

# sys.setrecursionlimit(300000)
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
sum = 0
for _ in range(int(input())):
    a,g = map(int,input().split())
    if sum+a <= 500:
        sum+=a
        print('A',end='')
    else:
        sum-=g
        print('G',end='')


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys

mod = 10 ** 9 + 7
mod1 = 998244353
# setrecursionlimit(300000)
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 1024

# sys.setrecursionlimit(300000)
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
sum = 0
for _ in range(int(input())):
    a,g = map(int,input().split())
    if sum+a <= 500:
        sum+=a
        print('A',end='')
    else:
        sum-=g
        print('G',end='')


import sys
sum = 0
for _ in range(int(input())):
    a,g = map(int,input().split())
    if sum+a <= 500:
        sum+=a
        sys.stdout.write("A")
    else:
        sum-=g
        sys.stdout.write("G")


import math
import heapq
import bisect
import sys
import collections
import fractions
import os
from io import BytesIO, IOBase

mod = 10 ** 9 + 7

BUFSIZE = 100

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
sum = 0
for _ in range(int(input())):
    a,g = map(int,input().split())
    if sum+a <= 500:
        sum+=a
        print('A',end='')
    else:
        sum-=g
        print('G',end='')


import sys

input = lambda: sys.stdin.readline().strip("\r\n")

n = int(input())
sa = 0
sg = 0
for i in range(n):
    p, q = map(int, input().split())
    if sg + p - sa <= 500:
        sg += p
        print("A", end="")
    else:
        sa += q
        print("G", end="")


import sys
def get_ints():
    return map(int, I().split())
def get_list():
    return list(map(int, I().split()))
def I():
    return sys.stdin.readline()
t =int(I())
sumA=0
for k in range(t):
    a, g = get_ints()
    if sumA +a <=500:
        print("A", end= "")
        sumA += a
    else:
        print("G", end= "")
        sumA -= g


t = int(input())
sumA = 0
sumG = 0
res =""
for k in range(t):
    a, g = list(map(int, input().split()))
    if sumA + a <= sumG + g:
        res += "A"
        sumA += a
    else:
        res += "G"
        sumG += g

print(res)


import sys
t = int(input())
sumA = 0
sumG = 0
for k in range(t):
    r = input().split()
    a = int(r[0])
    g = int(r[1])
    if sumA + a <= sumG + g and sumA - sumG <= 500:
        sys.stdout.write("A")
        sumA += a
    else:
        sys.stdout.write("G")
        sumG += g


t = int(input())
sumA = 0
sumG = 0
res = []
for k in range(t):
    a, g = list(map(int, input().split()))
    if sumA + a <= sumG + g and abs((sumA + a )- (sumG )) <= 500:
        res += ["A"]
        sumA += a
    else:
        res += ["G"]
        sumG += g
for j in res:
    print(j, end = "")


t = int(input())
sumA = 0
sumG = 0
res =""
for k in range(t):
    a, g = list(map(int, input().split()))
    if sumA + a <= sumG + g and abs((sumA + a )- (sumG )) <= 500:
        res += "A"
        sumA += a
    else:
        res += "G"
        sumG += g

print(res)


from sys import stdin
n=int(stdin.readline())
a=[]
flag=0
ans=[]
b,c=list(map(int,input().split()))

if b<=c:
	sum1=b
	ans.append('A')
else:
	sum2=c
	ans.append('G')

for i in range(1,n):
    b,c=list(map(int,stdin.readline().split()))
    if b+sum1-sum2<=500:
        sum1+=b
        ans.append('A')
    elif c+sum2-sum1<=500:
        sum2+=c
        ans.append('G')
    else:
        flag=1
        break
if flag==0:
    print(''.join(ans))
else:
    print(-1)


from sys import stdin
n=int(stdin.readline())
a=[]
flag=0
ans=[]
sum1=0
sum2=0
b,c=list(map(int,input().split()))

if b<=c:
	sum1=b
	ans.append('A')
else:
	sum2=c
	ans.append('G')

for i in range(1,n):
    b,c=list(map(int,stdin.readline().split()))
    if b+sum1-sum2<=500:
        sum1+=b
        ans.append('A')
    elif c+sum2-sum1<=500:
        sum2+=c
        ans.append('G')
    else:
        flag=1
        break
if flag==0:
    print(''.join(ans))
else:
    print(-1)


n=int(input())
a=[]
flag=0
for i in range(n):
    b,c=list(map(int,input().split()))
    a.append((b,c))
sum1=0
sum2=0
sum1=min(a[0])
ans=[]
ans.append('A')
for i in range(1,n):
    if a[i][0]+sum1-sum2<=500:
        sum1+=a[i][0]
        ans.append('A')
    elif a[i][1]+sum2-sum1<=500:
        sum2+=a[i][1]
        ans.append('G')
    else:
        flag=1
        break
if flag==0:
    print(''.join(ans))
else:
    print(-1)


n=int(input())
a=[]
flag=0
for i in range(n):
    b,c=list(map(int,input().split()))
    a.append((b,c))
sum1=0
sum2=0
sum1=min(a[0])
ans=[]
ans.append('A')
a.sort(key=lambda x:x[0])
for i in range(1,n):
    if a[i][0]+sum1-sum2<=500:
        sum1+=a[i][0]
        ans.append('A')
    elif a[i][1]+sum2-sum1<=500:
        sum2+=a[i][1]
        ans.append('G')
    else:
        flag=1
        break
if flag==0:
    print(''.join(ans))
else:
    print(-1)


from sys import stdin
n=int(stdin.readline())
a=[]
flag=1
for i in range(n):
    b,c=list(map(int,stdin.readline().split()))
    a.append((b,c))
sum1=0
sum2=0
sum1=min(a[0])
ans=[]
ans.append('A')
a.sort(key=lambda x:x[0])
for i in range(1,n):
    if a[i][0]+sum1-sum2<=500:
        sum1+=a[i][0]
        ans.append('A')
    elif a[i][1]+sum2-sum1<=500:
        sum2+=a[i][1]
        ans.append('G')
    else:
        flag=1
        break
if flag==0:
    print(''.join(ans))
else:
    print(-1)


from sys import stdin
n=int(stdin.readline())
a=[]
flag=0
ans=[]
b,c=list(map(int,input().split()))
sum1=min(b,c)
if b<=c:
	ans.append('A')
else:
	ans.append('G')
sum2=0

for i in range(1,n):
    b,c=list(map(int,stdin.readline().split()))
    if b+sum1-sum2<=500:
        sum1+=b
        ans.append('A')
    elif c+sum2-sum1<=500:
        sum2+=c
        ans.append('G')
    else:
        flag=1
        break
if flag==0:
    print(''.join(ans))
else:
    print(-1)


# include<iostream>
using namespace std;
int main()
    {
    long long int y,k,n,b,c;
    cin>>y>>k>>n;
    if(y==n || y>n)
            cout<<"-1";
    else
    {
    b=y%k;
    c=k-b;

    while((y+c) <= n)
               {
                     cout<<c<<" ";
                c=c+6;

                }
    }
    system("pause");
    }


# include<iostream>
using namespace std;
int main()
    {
   int y,k,n,count=0,i,c;
   cin>>y>>k>>n;
   c=n-y;
   if(y==n)
   cout<<"-1";
   else
  {
   for(i=1;i<=c;i++)
                    {
                     if((i+y)%k == 0)
                     {
                                cout<<i<<" ";
                                count=1;
                     }
                    }
                    if(count==0)
                    cout<<"-1";
   }
 //  system("pause");
    }


# include<iostream>
using namespace std;
int main()
    {
   int y,k,n,count=0,i,c;
   cin>>y>>k>>n;
   c=n-y;
   for(i=1;i<=c;i++)
                    {
                     if((i+y)%k == 0)
                     {
                                cout<<i<<" ";
                                count=1;
                     }
                    }
                    if(count==0)
                    cout<<"-1";

    }


# include<iostream>
using namespace std;
int main()
    {
    long long int y,k,n,b,c;
    cin>>y>>k>>n;
    if(y==n || y>n)
            cout<<"-1";
    else
    {
    b=y%k;
    c=k-b;

    while((y+c) <= n)
               {
                     cout<<c<<" ";
                c=c+6;

                }
    }

    }


# include<iostream>
using namespace std;
int main()
    {
   int y,k,n,count=0,i,c,b,x,d;
   cin>>y>>k>>n;
   if(y==n)
   cout<<"-1";
   else
  {
   b=y%k;
   x=k-b;
   d=n-y;
            while(x<=d)
                       {
                        cout<<x<<" ";
                        count=1;
                        x=x+k;
                        }
            if(count==0)
            cout<<"-1";
   }
 // system("pause");
    }


#include<iostream>
using namespace std;
int main()
{
    int y,k,n;
    cin>>y>>k>>n;
    int x=y%k;
    if(y-x+k>n)cout<<"-1"<<endl;
    else
    {
	for(int i=y-x+k;i<=n;i+=k)cout<<i-y<<" ";
	cout<<endl;
    }
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FORI(i,n) for(int i=0; i<n; ++i)
#define FORIR(i,n) for(int i=(n)-1; i>=0; --i)
#define MP(a,b) make_pair(a,b)
#define MT(a...) make_tuple(a)
#define ALL(L) (L).begin(),(L).end()
#define ALLR(L) (L).rbegin(),(L).rend()
#define SZ(L) (L).size()
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define SORTED_PAIR(a,b) MIN(a,b),MAX(a,b)
#define INF (1<<29)
#define EPS (1e-9)

typedef unsigned int uint;
typedef unsigned long long ull;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

int main() {
  ll y,k,n,x0;
  cin >> y >> k >> n;
  x0 = max(((1LL<<60) * k - y) % k, 1LL);
  if(x0 + y >= n) {
    cout << -1 << endl;
  } else {
    for(ll x = x0; x + y <= n; x += k) {
      cout << x << " ";
    }
    cout << endl;
  }
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FORI(i,n) for(int i=0; i<n; ++i)
#define FORIR(i,n) for(int i=(n)-1; i>=0; --i)
#define MP(a,b) make_pair(a,b)
#define MT(a...) make_tuple(a)
#define ALL(L) (L).begin(),(L).end()
#define ALLR(L) (L).rbegin(),(L).rend()
#define SZ(L) (L).size()
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define SORTED_PAIR(a,b) MIN(a,b),MAX(a,b)
#define INF (1<<29)
#define EPS (1e-9)

typedef unsigned int uint;
typedef unsigned long long ull;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

int main() {
  ll y,k,n,x0;
  cin >> y >> k >> n;
  x0 = ((1LL<<60) * k - y) % k;
  if(x0 + y >= n) {
    cout << -1 << endl;
  } else {
    for(ll x = x0; x + y <= n; x += k) {
      cout << x << " ";
    }
    cout << endl;
  }
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FORI(i,n) for(int i=0; i<n; ++i)
#define FORIR(i,n) for(int i=(n)-1; i>=0; --i)
#define MP(a,b) make_pair(a,b)
#define MT(a...) make_tuple(a)
#define ALL(L) (L).begin(),(L).end()
#define ALLR(L) (L).rbegin(),(L).rend()
#define SZ(L) (L).size()
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define SORTED_PAIR(a,b) MIN(a,b),MAX(a,b)
#define INF (1<<29)
#define EPS (1e-9)

typedef unsigned int uint;
typedef unsigned long long ull;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

int main() {
  ll y,k,n,x0;
  cin >> y >> k >> n;
  x0 = ((1LL<<11) * k - y) % k;
  x0 = (x0 > 0 ? x0 : k);
  cerr << "\t" << x0 << endl;
  if(x0 + y > n) {
    cout << -1 << endl;
  } else {
    for(ll x = x0; x + y <= n; x += k) {
      cout << x << " ";
    }
    cout << endl;
  }
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FORI(i,n) for(int i=0; i<n; ++i)
#define FORIR(i,n) for(int i=(n)-1; i>=0; --i)
#define MP(a,b) make_pair(a,b)
#define MT(a...) make_tuple(a)
#define ALL(L) (L).begin(),(L).end()
#define ALLR(L) (L).rbegin(),(L).rend()
#define SZ(L) (L).size()
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define SORTED_PAIR(a,b) MIN(a,b),MAX(a,b)
#define INF (1<<29)
#define EPS (1e-9)

typedef unsigned int uint;
typedef unsigned long long ull;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

int main() {
  ll y,k,n,x0;
  cin >> y >> k >> n;
  x0 = ((1LL<<11) * k - y) % k;
  x0 = (x0 > 0 ? x0 : k);
  cerr << "\t" << x0 << endl;
  if(x0 + y > n) {
    cout << -1 << endl;
  } else {
    for(ll x = x0; x + y <= n; x += k) {
      cout << x << " ";
    }
    cout << endl;
  }
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FORI(i,n) for(int i=0; i<n; ++i)
#define FORIR(i,n) for(int i=(n)-1; i>=0; --i)
#define MP(a,b) make_pair(a,b)
#define MT(a...) make_tuple(a)
#define ALL(L) (L).begin(),(L).end()
#define ALLR(L) (L).rbegin(),(L).rend()
#define SZ(L) (L).size()
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define SORTED_PAIR(a,b) MIN(a,b),MAX(a,b)
#define INF (1<<29)
#define EPS (1e-9)

typedef unsigned int uint;
typedef unsigned long long ull;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

int main() {
  ll y,k,n,x0;
  cin >> y >> k >> n;
  x0 = max(((1LL<<11) * k - y) % k, 1LL);
  cerr << "\t" << x0 << endl;
  if(x0 + y > n) {
    cout << -1 << endl;
  } else {
    for(ll x = x0; x + y <= n; x += k) {
      cout << x << " ";
    }
    cout << endl;
  }
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FORI(i,n) for(int i=0; i<n; ++i)
#define FORIR(i,n) for(int i=(n)-1; i>=0; --i)
#define MP(a,b) make_pair(a,b)
#define MT(a...) make_tuple(a)
#define ALL(L) (L).begin(),(L).end()
#define ALLR(L) (L).rbegin(),(L).rend()
#define SZ(L) (L).size()
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define SORTED_PAIR(a,b) MIN(a,b),MAX(a,b)
#define INF (1<<29)
#define EPS (1e-9)

typedef unsigned int uint;
typedef unsigned long long ull;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

int main() {
  ll y,k,n,x0;
  cin >> y >> k >> n;
  x0 = max(((1LL<<31) * k - y) % k, 1LL);
  if(x0 + y >= n) {
    cout << -1 << endl;
  } else {
    for(ll x = x0; x + y <= n; x += k) {
      cout << x << " ";
    }
    cout << endl;
  }
}


#include <iostream>
#include <algorithm>
#include <string>

int main()
{
	int y , k , n ; std::cin >> y >> k >> n ;
	int x = k - ( y % k ) ;
	n -= y ;
	bool volt = false ;
	for( ; x <= n ; x += k )
	{
		std::cout << x << " " ;
		volt = true ;
	}
	if( false == volt ) { std::cout << "-1" ; }
	std::cout << "\n" ;

	return 0 ;
}


#include <iostream>

using namespace std;

int main()
{
    int y,k,n,z=1;
    bool p=0;
    cin>>y>>k>>n;
    while (k*z<=n)
    {
        if (k*z>y) {cout<<(k*z)-y<<" "; p=1; }
        z++;
    }

    if (p==0) cout<<-1<<endl;

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int y,k,n;
    bool p=0;
    cin>>y>>k>>n;
    for (int i=y+1,x=1;i<=n;i++,x++)
    {
        if ((y+x)%k==0) {cout<<x<<" "; p=1;}
    }

    if (p==0) cout<<-1<<endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <numeric>
#include <cassert>
#include <random>
#include <stdarg.h>
#include <string.h>
#include <stack>
#include <string>
#include <map>
#include <stdio.h>
#include <fstream>
#include <limits.h>
#include <set>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <functional>

#define int long long int

#define DEBUG
#define NULL 0

#include <iostream>
#include <vector>
using namespace std;

vector<int> indexOf(char* str, char* pattern)
{
	vector<int> v;
	int slen = strlen(str);
	int patlen = strlen(pattern);
	for(int i = 0; i<slen; i++) {
		bool match = true;
		for(int j = 0; j<patlen; j++) {
			if(str[i+j] != pattern[j]) {
				match = false;
			}
		}
		if(match) {
			v.push_back(i);
		}
	}
	return v;
}

int maxBorder(char* a)
{
	int len = strlen(a);

	char* pref = new char[len];
	char* suff = new char[len];

	int max = 0;

	for(int i = 0; i<len; i++) {
		copy(a, a+i, pref);
		pref[i] = '\0';

		copy(a+len-i, a+len, suff);
		suff[i] = '\0';

		if(!strcmp(pref, suff)) {
			max = strlen(pref);
		}
	}

	delete[] pref;
	delete[] suff;
	return max;
}

int* getBordersArray(char* str)
{
	int len = strlen(str);
	int* res = new int[len]();
	char* buf = new char[len];
	for(int i = 0; i<len; i++) {
		copy(str, str+i+1, buf);
		buf[i+1] = '\0';
		int max = maxBorder(buf);
		res[i] = max;
	}
	return res;
}

int* getBordersArrayDP(char* str)
{
	int len = strlen(str);
	int* dp = new int[len]();
	for(int i = 1; i<len; i++) {
		int index = dp[i-1];
		while(1) {
			if(str[index] == str[i]) {
				dp[i] = index + 1;
				break;
			}
			if(index > 0) {
				index = dp[index - 1];
			} else {
				break;
			}
		}
	}
	return dp;
}

ostream_iterator<int> oi(cout, " ");

class Pair;

class Item
{
	friend ostream &operator<< ( ostream & out, const Pair & c );
	friend istream &operator>> ( istream & out, Pair & c );

public:
	Item(string des) {
		description = des;
	}

	int keyF() {
		key = description.length();
		return key;
	}

	string toString() {
		return description;
	}

	int key;

	string description;
};

ostream & operator<<( ostream & out, const Item & c  )
{
	out << c.description;
	return out;
}

istream & operator>>( istream & in, Item & c  )
{
	in>>c.description;
	return in;
}

ostream & operator<<( ostream & out, pair<int, int>& c  )
{
	out << "<" <<c.first << ", ";
	out << c.second << ">" << endl;
	return out;
}

istream & operator>>( istream & in, pair<int, int>& c  )
{
	in>>c.first;
	in>>c.second;
	return in;
}

void print()
{
	std::cout << endl;
}

template<typename A>
void print(A value)
{
	std::cout << value;
}

template<typename A, typename B>
void print(A value1, B value2)
{
	cout << value1 << " " << value2;
}

template<typename A, typename B, typename C>
void print(A value1, B value2, C value3)
{
	cout << value1 << " " << value2 << " " << value3;
}

template<typename A, typename B, typename C, typename D>
void print(A value1, B value2, C value3, D value4)
{
	cout << value1 << " " << value2 << " " << value3 << " " << value4;
}

template<typename E>
E read()
{
	E value;
	cin >> value;
	return value;
}

string readString()
{
	char* s = new char[1000];
	fgets(s, 1000, stdin);
	return string(s);
}

template<typename A>
void println(A value)
{
	std::cout << value << endl;
}

template<typename A, typename B>
void println(A value1, B value2)
{
	cout << value1 << " " << value2 << endl;
}

template<typename A, typename B, typename C>
void println(A value1, B value2, C value3)
{
	cout << value1 << " " << value2 << " " << value3 << endl;
}

template<typename A, typename B, typename C, typename D>
void println(A value1, B value2, C value3, D value4)
{
	cout << value1 << " " << value2 << " " << value3 << " " << value4 << endl;
}

int randomint(int min, int max)
{
	if(max == min) {
		return max;
	}
	return rand()%(max-min+1)+min;
}

class Pair
{
	friend ostream &operator<< ( ostream & out, const Pair & c );
	friend istream &operator>> ( istream & out, Pair & c );

public:
	Pair(Item* p);
	int key;
	Item* value;
};

Pair::Pair(Item* b)
{
	key = b->key;
	value = b;
}

ostream & operator<<( ostream & out, const Pair& c  )
{
	out<< "(" << c.value->key << " -> " << (c.value->toString()) << ")";
	return out;
}

ostream & operator<<( ostream & out, string& c  )
{
	out << c.data() << endl;
	return out;
}

template<typename E>
class Array
{
public:
	int size;
	Array<E>(int _capacity) {
		capacity = _capacity;
		array = new E[capacity];
		size = capacity;
		for(int i =0; i<size; i++) {
			array[i] = NULL;
		}
	}

	void sort() {
		std::sort(&array[0], &array[size]);
	}

	Array() {
		capacity = 1024;
		array = new E[capacity];
		size = 0;
	}

	Array(vector<E>& vect) {
		int _size = vect.size();
		capacity = _size*2;
		size = _size;
		array = new E[capacity];
		for(int i =0; i<size; i++) {
			array[i] = vect[i];
		}
	}

	Array(int minBound, int maxBound, int _size) {
		srand(_size);
		capacity = _size*2;
		size = _size;
		array = new E[capacity];
		for(int i = 0; i<size; i++) {
			array[i] = randomint(minBound, maxBound);
		}
	}

	void add(E item);
	int leftBinarySearch(E& item);
	int rightBinarySearch(E& item);
	pair<int, int> equalRange(E& item);
	bool binarySearch(E& item);
	E* begin();
	E* end();
	vector<E> toVector();
	void toString();
	E& operator[](int i);
	E& index(int i);
	E* array;
	void null(void) {
		for(int i =0; i<size; i++) {
			array[i] = NULL;
		}
	}
private:
	int capacity;
	void ensureCapacity(int cap);
};

template <typename E>
void Array<E>::ensureCapacity(int cap)
{
	capacity = capacity*2;
	E* newArray = new E[capacity];
	memcpy(newArray, array, sizeof(E)*size);
	delete[] array;
	array = newArray;
}

template <typename E>
void Array<E>::toString()
{
	int i = 0;
	E* begin = array;
	cout << "[";
	while(i<size) {
		if(i == size-1) {
			cout << *array;
		} else {
			cout << *array << " ";
		}
		array++;
		i++;
	}
	cout << "]";
	cout << endl;
	array = begin;
}

template <typename E>
void Array<E>::add(E item)
{
	if(capacity<size+1) {
		ensureCapacity(size+1);
	}
	array[size] = item;
	size++;
}

template <typename E>
E* Array<E>::begin()
{
	return array;
}

template <typename E>
E* Array<E>::end()
{
	return array + size;
}

template <typename E>
int Array<E>::leftBinarySearch(E& item)
{
	return lower_bound(array, array+size, item)-array;
}

template <typename E>
int Array<E>::rightBinarySearch(E& item)
{
	return upper_bound(array, array+size, item)-array;
}

template <typename E>
pair<int, int> Array<E>::equalRange(E& item)
{
	pair<int*, int*> p(0, 0);
	p = equal_range(array, array + size, item);
	return make_pair(p.first - array, p.second - array);
}

template <typename E>
bool Array<E>::binarySearch(E& item)
{
	return binary_search(array, array + size, item);
}

template <typename E>
vector<E> Array<E>::toVector()
{
	vector<E> res = vector<E>(size);
	for(int i =0; i<res.size(); i++) {
		res[i] = array[i];
	}
	return res;
}

template<typename T>
ostream & operator<<( ostream & out, Array<T>& c  )
{
	for(int i = 0; i<c.size; i++) {
		out << c[i] << " ";
	}
	return out;
}

ostream & operator<<( ostream & out, Array< pair<int, int> >& c  )
{
	for(int i = 0; i<c.size; i++) {
		out << c[i];
	}
	return out;
}

template<typename T>
istream & operator>>( istream & in, Array<T>& c  )
{
	for(int i = 0; i<c.size; i++) {
		in >> c[i];
	}
	return in;
}

ostream & operator<<( ostream & out, map<int, int>& c  )
{
	map<int, int>::iterator it = c.begin();
	while(it!=c.end()) {
		pair<int, int> entry = *it;
		out << entry;
		it++;
	}
	return out;
}

template <typename E>
E& Array<E>::operator[] (int i)
{
#ifdef DEBUG
	if(i<size && i>=0) {
		return array[i];
	} else {
		cout << "Array index out of bounds, index is " << i << ", size is " << size << endl;
		cout << "Array is " << endl;
		toString();
		assert(0);
	}
#endif

#ifndef DEBUG
	return array[i]
#endif
}

       template<typename E>
class Matrix
{
public:
	int rows;
	int columns;
	Array<E> array;

	E& get(int x, int y);
	void set(int x, int y, E& value);
	E& operator()(int x, int y);
	Matrix<E> transpose();

	pair<E*, E*> getRow(int y);

	Matrix<E>(int c, int r) {
		rows = r;
		columns = c;
		array = Array<E>(rows*columns);
		array.null();
	}

	void swap(Matrix<E>& other) {
		std::swap(array, other.array);
		std::swap(rows, other.rows);
		std::swap(columns, other.columns);
	}

	Matrix<E>(int _columns, int _rows, int minBound, int maxBound) {
		rows = _rows;
		columns = _columns;
		int size = _rows*_columns;
		array = Array<E>(minBound, maxBound, size);
	}

private:
};

template<typename E>
Matrix<E> Matrix<E>::transpose()
{
	Matrix<int> b(rows, columns);
	for(int x = 0; x<columns; x++) {
		for(int y = 0; y<rows; y++) {
			b(y, x) = array.array[x+y*columns];
		}
	}
	return b;
}

template <typename E>
E& Matrix<E>::operator()(int x, int y)
{
#ifdef DEBUG
	if(x>=columns || x<0) {
		cout << "x must be in range [0; " << columns - 1 << "], but it is " << x << endl;
		assert(0);
	}
	if(y>=rows || y<0) {
		cout << "y must be in range [0; " << rows - 1 << "], but it is " << y << endl;
		assert(0);
	}
	return array.array[x+y*columns];
#endif
#ifndef DEBUG
	return array.array[x+y*columns];
#endif
}

template<typename T>
istream & operator>>( istream & in, Matrix<T>& c  )
{
	for(int y = 0; y<c.rows; y++) {
		for(int x = 0; x<c.columns; x++) {
			in >> c(x, y);
		}
	}
	return in;
}

template<typename E>
pair<E*, E*> Matrix<E>::getRow(int y)
{
	E* f = array.array + y*columns;
	E* s = array.array + (y+1)*columns;
	pair<E*, E*> p(f, s);
	return p;
}

template<typename T>
ostream & operator<<( ostream & out, Matrix<T>& c  )
{
	for(size_t y = 0; y<c.rows; y++) {
		for(size_t x = 0; x<c.columns; x++) {
			out << c(x, y) << " ";
		}
		out << endl;
	}
}

int bpow(int a, int b)
{
	if(b == 0) {
		return 1;
	} else {
		if(b%2 == 0) {
			int half = bpow(a, b/2);
			return half*half;
		} else {
			return bpow(a, b-1)*a;
		}
	}
}

int fact(int n)
{
	if(n == 1) {
		return 1;
	} else {
		return n*fact(n-1);
	}
}

int gcd(int a, int b)
{
	if(!b) {
		return a;
	} else {
		return gcd(b, a%b);
	}
}

Array<pair<int, int> > factorize(int n)
{
	Array<pair<int, int> > res;
	for(int i = 2; i<sqrt((double)n)+1; i++) {
		if(n%i == 0) {
			pair<int, int> comp = make_pair(i, 1);
			n/=i;
			while(n%i == 0) {
				comp.second++;
				n/=i;
			}
			res.add(comp);
		}
	}

	if(n>1) {
		res.add(make_pair(n, 1));
	}
	return res;
}

int euler(int n)
{
	Array<pair<int, int> > fact = factorize(n);
	int res = 1;
	for(unsigned int i = 0; i<fact.size; i++) {
		int factor = pow((double)fact[i].first, (double)fact[i].second)-pow((double)fact[i].first, (double)fact[i].second-1);
		res*=factor;
	}
	return res;
}

int inversePrime(int a, int m)
{
	return bpow(a, m-2)%m;
}

int inverseCoprimes(int a, int m)
{
	return bpow(a, euler(m)-1)%m;
}

int inverse(int a, int m)
{
	if(gcd(a, m) == 1) {
		return inverseCoprimes(a, m);
	} else {
		assert(0);
		return -1;
	}
}

Array<int> enumerateDivisors(int n)
{
	Array<pair<int, int> > divs = factorize(n);
	vector<int> totals = vector<int>(divs.size+1);
	totals[0] = 1;
	for(unsigned int i = 1; i < divs.size+1; i++) {
		totals[i]=totals[i-1]*(divs[i-1].second+1);
	}

	Array<int> res;
	for(int i = 0; i<totals[totals.size()-1]; i++) {
		vector<int> values = vector<int>(divs.size);
		for(unsigned int j = 0; j<values.size(); j++) {
			values[j] = (i/totals[j])%(divs[j].second+1);
		}
		int r = 1;
		for(unsigned int i = 0; i<values.size(); i++) {
			r*=bpow(divs[i].first, values[i]);
		}
		res.add(r);
	}
	return res;
}

istream& operator>>( istream& in, Pair& c  )
{
	in >> c.value->description;
	c.value->key = c.value->keyF();
	return in;
}

void reverse(char *str)
{
	char temp;
	size_t len = strlen(str) - 1;
	size_t i;
	size_t k = len;

	for(i = 0; i < len; i++) {
		temp = str[k];
		str[k] = str[i];
		str[i] = temp;
		k--;
		if(k == (len / 2)) {
			break;
		}
	}
}

map<int, int> count(Array<int> a)
{
	map<int, int> res;
	for(int i = 0; i<a.size; i++) {
		res[a[i]]++;
	}
	return res;
}

void itoa(int n, char s[])
{
	int radix = 10;
	int i, sign;

	if ((sign = n) < 0)
		n = -n;
	i = 0;
	do {
		s[i++] = n % radix + '0';
	} while ((n /= radix) > 0);
	if (sign < 0)
		s[i++] = '-';
	s[i] = '\0';
	reverse(s);
}

int* vectorToArray(vector<int> v)
{
	int* a = new int[v.size()];
	for(unsigned int i = 0; i<v.size(); i++) {
		a[i] = v[i];
	}
	return a;
}

char* stringToNumber(int number)
{
	char* res = new char[100];
	itoa(number, res);
	return res;
}

int numberToString(char* str)
{
	return atoi(str);
}

int booleanAnswerBinarySearch(Array<int> params, int left, int right, bool (*f)(Array<int> params, int v))
{
	if(f(params, left) && !f(params, left-1)) {
		return left;
	}

	if(f(params, right) && !f(params, right+1)) {
		return right;
	}

	int middle = (left+right)/2;
	int g = f(params, middle);
	if(g) {
		return booleanAnswerBinarySearch(params, left, middle, f);
	} else {
		return booleanAnswerBinarySearch(params, middle+1, right, f);
	}
}

Array< Array<int> > enumerarePermutations(int n)
{
	int fac = fact(n);
	Array<int> v;
	for(int i = 0; i<n; i++) {
		v.add(i+1);
	}
	Array< Array <int> > res;
	for(int i = 0; i<fac-1; i++) {
		Array<int> c(n);
		copy(v.array, v.array + v.size, c.array);
		res.add(c);
		next_permutation(v.array, v.array + v.size);
	}
	Array<int> c(n);
	copy(v.array, v.array + v.size, c.array);
	res.add(c);
	return res;
}

Array< Array<int> > enumerarePermutations(Array<int> array)
{
	int n = array.size;
	int fac = fact(n);
	Array<int> v;
	for(int i = 0; i<n; i++) {
		v.add(array[i]);
	}
	Array< Array <int> > res;
	for(int i = 0; i<fac-1; i++) {
		Array<int> c(n);
		copy(v.array, v.array + v.size, c.array);
		res.add(c);
		next_permutation(v.array, v.array + v.size);
	}
	Array<int> c(n);
	copy(v.array, v.array + v.size, c.array);
	res.add(c);
	return res;
}

Array< Array<int> > enumerareTuples(int n, int k)
{
	int q = bpow(k, n);
	Array< Array<int> > res(q);
	for(int i = 0; i<q; i++) {
		Array<int> tuple(n);
		for(int j = 0; j<n; j++) {
			tuple[j] = (i/bpow(k, j))%k;
		}
		res[i] = tuple;
	}
	return res;
}

Array< Array<int> > enumerareTuples(int n, Array<int> array)
{
	int k = array.size;
	int q = bpow(k, n);
	Array< Array<int> > res(q);
	for(int i = 0; i<q; i++) {
		Array<int> tuple(n);
		for(int j = 0; j<n; j++) {
			tuple[j] = array[(i/bpow(k, j))%k];
		}
		res[i] = tuple;
	}
	return res;
}

Array<int> sieve(int bound)
{
	bool* array = new bool[bound+1]();
	for(int i = 2; i*i<=bound; i++) {
		if(!array[i]) {
			for(int j = i+i; j<=bound; j+=i) {
				array[j] = 1;
			}
		}
	}

	Array<int> res;
	for(int i = 2; i<=bound; i++) {
		if(!array[i]) {
			res.add(i);
		}
	}
	return res;
}

int f(int k)
{
	return k&(k+1);
}

string alignLeft(string a, int length, char ch)
{
	if(a.length() < length) {
		a = string(length - a.length(), ch) + a;
	}
	return a;
}

string decToRadix(int n, int radix)
{
	string res("");
	if(n == 0) {
		res.push_back('0');
		return res;
	}
	while(n) {
		int digit = n%radix;
		res.push_back((char)(digit + '0'));
		n/=radix;
	}
	reverse(res.begin(), res.end());
	return res;
}

int radixToDec(string s, int radix)
{
	int res = 0;
	reverse(s.begin(), s.end());
	for(int i = 0; i<s.length(); i++) {
		res+=(s[i]-'0')*bpow(radix, i);
	}
	return res;
}

class F
{
public:
	int (*f)(int, int);
	int (*inverse)(int, int);
	int NEUTRAL;

	F(int(*pf)(int, int), int (*pinverse)(int, int), int n) {
		f = pf;
		inverse = pinverse;
		NEUTRAL = n;
	}

	F() {
	}

	int operator()(int a, int b) {
		return f(a, b);
	}

	int inversed(int a, int b) {
		return inverse(a, b);
	}
};

class BIT
{
public:
	F f;
	Array<int> tree;
	Array<int> array;

	BIT(F func, Array<int> source) {
		Array<int> arr(source.size);
		copy(source.begin(), source.end(), arr.begin());
		array = arr;
		f = func;

		Array<int> tr(source.size);
		tree = tr;

		for(int i = 0; i<source.size; i++) {
			add(i, array[i]);
		}
	}

	void add(int i, int delta) {
		for(int u = i; u<tree.size; u = u | (u+1)) {
			tree[u]=f(tree[u], delta);
		}
	}

	int value(int l, int r) {
		return f.inversed(p(r) , p(l - 1));
	}

	int p(int v) {
		if(v < 0) {
			return 0;
		}
		if(v == 0) {
			return tree[0];
		} else {
			return f(tree[v], p((v&(v+1)) - 1));
		}
	}
};

#undef int
int main(void)
{
	#define int long long int

	int y, k, n;
	cin >> y >> k >> n;
	vector<int> res;

	for(int r = 0; r<=n/k; r++){
		int count = r*k;
		if(count > y){
			res.push_back(count - y);
		}
	}

	if(res.size() == 0){
		print(-1);
	}
	else{
		copy(res.begin(), res.end(), oi);
	}
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
#include<iostream>
using namespace std;

#define rep(i,n) for(int i=0; i<(int)n; i++)
#define st first
#define nd second
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpii;
typedef set<int> SI;

#ifdef DEBUG
const bool debug = true;
#else
const bool debug = false;
#endif
const int inf = 1000 * 1000 * 1000 ;
const int MAKSN = 1000 * 1000 + 13; // UZUPElnic

int a,b,n;
long long wyd,m,k;
int y;
int ans = 0;
void readIn()
{
	cin>>y>>k>>n;
}

void solve()
{
	int pot =0;

	while(pot<y)
	{
		pot += k;
	}

	n-= y;
	pot -= y;

	if(pot == 0 ) pot+=k;
	while(pot <= n)
	{
		cout<<pot<<" ";
		pot += k;
		ans ++;
	}

	if(ans == 0) cout<<"-1\n";
}

int main()
{
	readIn();
	solve();
	return 0;
}


#include<iostream>
using namespace std;
int main() {
long long y,k,n;
    cin>>y>>k>>n;
    long long n1=y/k;
    bool flag=false;
    while (true) {
        if (n1*k>n) break;
        if (n1*k>y) {
            flag=true;
            cout<<n1*k-y<<" ";
        }
        n1++;
    }
    if (!flag) {
        cout<<-1<<endl;
    }
}


#include <cstdio>

int main()
{
    int y, k, n;
    scanf("%d%d%d", &y, &k, &n);
    int x = k - y % k;
    int top = n - y;
    if (x <= top)
    {
        printf("%d", x);
        x += k;
        while (x <= top)
        {
            printf(" %d", x);
            x += k;
        }
        printf("\n");
    }
    else
    {
        printf("-1\n");
    }
    return 0;
}