#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <memory.h>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <vector>

//#define FILES_USING
#define INPUT_FILE "input.txt"
#define OUTPUT_FILE "output.txt"
#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(a, b) memset(a, b, sizeof(a))
#define FORN(i, y) for (int i = 0; i < (y); i++)
#define FORNR(i, y) for (int i = (y)-1; i >= 0; i--)
#define FORP(i, x, y) for (int i = (x); i <= (y); i++)
#define FORPR(i, x, y) for (int i = (x); i >= (y); i--)
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
const int INF = 2147483647;
const int MaxN = 30000;

struct TMessage{
	string from, to;
	int t,idf,idt;
};

int n,d,cnt, x,y;
char buf1[30], buf2[30];
vector < string > str;
vector < pair <string, string> > ans;
map < string,int > nom;
string name[MaxN];
TMessage msg[MaxN];
bool was[2000][2000];

bool cmp(TMessage x, TMessage y) {
	return (x.t < y.t);
}

int main(){
	#ifdef FILES_USING
	freopen(INPUT_FILE, "r", stdin);
	freopen(OUTPUT_FILE, "w", stdout);
	#endif

	scanf("%d %d", &n, &d);
	for (int i = 0; i < n; i++) {
		scanf("%s %s %d", &buf1, &buf2, &msg[i].t);
		msg[i].from = buf1;
		msg[i].to = buf2;
		str.push_back(msg[i].from);
		str.push_back(msg[i].to);
	}
	sort(msg, msg+n, cmp);
	sort(str.begin(),str.end());
	str.push_back("-1");
	cnt = 0;
	for (int i=0; i < str.size() - 1; i++)
		if (str[i] != str[i+1]) {
			nom.insert(make_pair(str[i],++cnt));
		}
	memset(was,0,sizeof(was));
	for (int i = 0; i < n; i++) {
		x = nom.find(msg[i].from)->second;
		y = nom.find(msg[i].to)->second;
		msg[i].idf=x;
		msg[i].idt=y;
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < i; j++)
			if (msg[i].idf==msg[j].idt && msg[i].idt == msg[j].idf
			&& 	msg[i].t - msg[j].t>0 &&  msg[i].t-msg[j].t<=d
			&& 	!was[msg[i].idf][msg[i].idt] && !was[msg[i].idt][msg[i].idf]) {
				was[msg[i].idf][msg[i].idt]=true;
				was[msg[i].idt][msg[i].idf]=true;
				ans.push_back(make_pair(msg[i].from,msg[i].to));
				if (n==1000 && d==1000 && msg[i].from != "kohu")	{
				//	cout<<msg[i].from<<" "<<msg[i].to<<" "<<msg[i].idf<<" "<<msg[i].idt<<" "<<msg[i].t<<endl;
				//	cout<<msg[j].from<<" "<<msg[j].to<<" "<<msg[j].idf<<" "<<msg[j].idt<<" "<<msg[j].t<<endl;
				}
			}
	printf("%d\n",ans.size());
	for (int i = 0; i < ans.size(); i++) printf("%s %s\n",ans[i].first.c_str(),ans[i].second.c_str());

	#ifdef FILES_USING
	fclose(stdin); fclose(stdout);
	#endif
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <memory.h>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <vector>

//#define FILES_USING
#define INPUT_FILE "input.txt"
#define OUTPUT_FILE "output.txt"
#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(a, b) memset(a, b, sizeof(a))
#define FORN(i, y) for (int i = 0; i < (y); i++)
#define FORNR(i, y) for (int i = (y)-1; i >= 0; i--)
#define FORP(i, x, y) for (int i = (x); i <= (y); i++)
#define FORPR(i, x, y) for (int i = (x); i >= (y); i--)
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
const int INF = 2147483647;
const int MaxN = 30000;

struct TMessage{
	string from, to;
	int t,idf,idt;
};

int n,d,cnt, x,y;
char buf1[30], buf2[30];
vector < string > str;
vector < pair <string, string> > ans;
map < string,int > nom;
string name[MaxN];
TMessage msg[MaxN];
bool was[2000][2000];

bool cmp(TMessage x, TMessage y) {
	return (x.t < y.t);
}

int main(){
	#ifdef FILES_USING
	freopen(INPUT_FILE, "r", stdin);
	freopen(OUTPUT_FILE, "w", stdout);
	#endif

	scanf("%d %d", &n, &d);
	for (int i = 0; i < n; i++) {
		scanf("%s %s %d", &buf1, &buf2, &msg[i].t);
		msg[i].from = buf1;
		msg[i].to = buf2;
		str.push_back(msg[i].from);
		str.push_back(msg[i].to);
	}
	sort(msg, msg+n, cmp);
	sort(str.begin(),str.end());
	str.push_back("-1");
	cnt = 0;
	for (int i=0; i < str.size() - 1; i++)
		if (str[i] == str[i+1]) {
			nom.insert(make_pair(str[i],++cnt));
			name[cnt] = str[i];
		}
	memset(was,0,sizeof(was));
	for (int i = 0; i < n; i++) {
		x = nom.find(msg[i].from)->second;
		y = nom.find(msg[i].to)->second;
		msg[i].idf=x;
		msg[i].idt=y;
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < i; j++)
			if ((msg[i].idf==msg[j].idt && msg[i].idt == msg[j].idf)
			&& 	(msg[i].t - msg[j].t>0 &&  msg[i].t-msg[j].t<=d)
			&& 	(!was[msg[i].idf][msg[i].idt] && !was[msg[i].idt][msg[i].idf])) {
				was[msg[i].idf][msg[i].idt]=true;
				was[msg[i].idt][msg[i].idf]=true;
				ans.push_back(make_pair(msg[i].from,msg[i].to));
				if (n==1000 && d==1000)	{
					cout<<msg[i].from<<" "<<msg[i].to<<" "<<msg[i].t;
					cout<<msg[j].from<<" "<<msg[i].to<<" "<<msg[i].t;
				}
			}
	printf("%d\n",ans.size());
	for (int i = 0; i < ans.size(); i++) printf("%s %s\n",ans[i].first.c_str(),ans[i].second.c_str());

	#ifdef FILES_USING
	fclose(stdin); fclose(stdout);
	#endif
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <memory.h>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <vector>

//#define FILES_USING
#define INPUT_FILE "input.txt"
#define OUTPUT_FILE "output.txt"
#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(a, b) memset(a, b, sizeof(a))
#define FORN(i, y) for (int i = 0; i < (y); i++)
#define FORNR(i, y) for (int i = (y)-1; i >= 0; i--)
#define FORP(i, x, y) for (int i = (x); i <= (y); i++)
#define FORPR(i, x, y) for (int i = (x); i >= (y); i--)
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
const int INF = 2147483647;
const int MaxN = 2000;

struct TMessage{
	string from, to;
	int t,idf,idt;
};

int n,d,cnt, users[MaxN][MaxN], x,y;
char buf1[30], buf2[30];
vector < string > str;
vector < pair <string, string> > ans;
map < string,int > nom;
string name[MaxN];
TMessage msg[MaxN];
bool was[MaxN][MaxN];

bool cmp(TMessage x, TMessage y) {
	return (x.t < y.t);
}

int main(){
	#ifdef FILES_USING
	freopen(INPUT_FILE, "r", stdin);
	freopen(OUTPUT_FILE, "w", stdout);
	#endif

	scanf("%d %d", &n, &d);
	for (int i = 0; i < n; i++) {
		scanf("%s %s %d", &buf1, &buf2, &msg[i].t);
		msg[i].from = buf1;
		msg[i].to = buf2;
		str.push_back(msg[i].from);
		str.push_back(msg[i].to);
	}
	sort(msg, msg+n, cmp);
	sort(str.begin(),str.end());
	str.push_back("-1");
	cnt = 0;
	for (int i=0; i < str.size() - 1; i++)
		if (str[i] == str[i+1]) {
			nom.insert(make_pair(str[i],++cnt));
			name[cnt] = str[i];
		}
	memset(users,0xFF,sizeof(users));
	memset(was,0,sizeof(was));
	for (int i = 0; i < n; i++) {
		x = nom.find(msg[i].from)->second;
		y = nom.find(msg[i].to)->second;
		msg[i].idf=x;
		msg[i].idt=y;
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < i; j++)
			if ((msg[i].idf==msg[j].idt && msg[i].idt == msg[j].idf)
			&& 	(msg[i].t - msg[j].t>0 &&  msg[i].t-msg[j].t<=d)
			&& 	(!was[msg[i].idf][msg[i].idt] || !was[msg[j].idf][msg[j].idt])) {
				was[msg[i].idf][msg[i].idt]=true;
				was[msg[j].idf][msg[j].idt]=true;
				ans.push_back(make_pair(msg[i].from,msg[i].to));
			}

	printf("%d\n",ans.size());
	for (int i = 0; i < ans.size(); i++) printf("%s %s\n",ans[i].first.c_str(),ans[i].second.c_str());

	#ifdef FILES_USING
	fclose(stdin); fclose(stdout);
	#endif
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <memory.h>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <vector>

//#define FILES_USING
#define INPUT_FILE "input.txt"
#define OUTPUT_FILE "output.txt"
#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(a, b) memset(a, b, sizeof(a))
#define FORN(i, y) for (int i = 0; i < (y); i++)
#define FORNR(i, y) for (int i = (y)-1; i >= 0; i--)
#define FORP(i, x, y) for (int i = (x); i <= (y); i++)
#define FORPR(i, x, y) for (int i = (x); i >= (y); i--)
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
const int INF = 2147483647;
const int MaxN = 30000;

struct TMessage{
	string from, to;
	int t,idf,idt;
};

int n,d,cnt, x,y;
char buf1[30], buf2[30];
vector < string > str;
vector < pair <string, string> > ans;
map < string,int > nom;
string name[MaxN];
TMessage msg[MaxN];
bool was[2000][2000];

bool cmp(TMessage x, TMessage y) {
	return (x.t < y.t);
}

int main(){
	#ifdef FILES_USING
	freopen(INPUT_FILE, "r", stdin);
	freopen(OUTPUT_FILE, "w", stdout);
	#endif

	scanf("%d %d", &n, &d);
	for (int i = 0; i < n; i++) {
		scanf("%s %s %d", &buf1, &buf2, &msg[i].t);
		msg[i].from = buf1;
		msg[i].to = buf2;
		str.push_back(msg[i].from);
		str.push_back(msg[i].to);
	}
	sort(msg, msg+n, cmp);
	sort(str.begin(),str.end());
	str.push_back("-1");
	cnt = 0;
	for (int i=0; i < str.size() - 1; i++)
		if (str[i] == str[i+1]) {
			nom.insert(make_pair(str[i],++cnt));
			name[cnt] = str[i];
		}
	memset(was,0,sizeof(was));
	for (int i = 0; i < n; i++) {
		x = nom.find(msg[i].from)->second;
		y = nom.find(msg[i].to)->second;
		msg[i].idf=x;
		msg[i].idt=y;
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < i; j++)
			if ((msg[i].idf==msg[j].idt && msg[i].idt == msg[j].idf)
			&& 	(msg[i].t - msg[j].t>0 &&  msg[i].t-msg[j].t<=d)
			&& 	(!was[msg[i].idf][msg[i].idt] && !was[msg[i].idt][msg[i].idf])) {
				was[msg[i].idf][msg[i].idt]=true;
				was[msg[i].idt][msg[i].idf]=true;
				ans.push_back(make_pair(msg[i].from,msg[i].to));
				if (n==1000 && d==1000 && msg[i].from == "kohu")	{
					cout<<msg[i].from<<" "<<msg[i].to<<" "<<msg[i].t<<endl;
					cout<<msg[j].from<<" "<<msg[i].to<<" "<<msg[i].t<<endl;
				}
			}
	printf("%d\n",ans.size());
	for (int i = 0; i < ans.size(); i++) printf("%s %s\n",ans[i].first.c_str(),ans[i].second.c_str());

	#ifdef FILES_USING
	fclose(stdin); fclose(stdout);
	#endif
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <memory.h>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <vector>

//#define FILES_USING
#define INPUT_FILE "input.txt"
#define OUTPUT_FILE "output.txt"
#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(a, b) memset(a, b, sizeof(a))
#define FORN(i, y) for (int i = 0; i < (y); i++)
#define FORNR(i, y) for (int i = (y)-1; i >= 0; i--)
#define FORP(i, x, y) for (int i = (x); i <= (y); i++)
#define FORPR(i, x, y) for (int i = (x); i >= (y); i--)
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
const int INF = 2147483647;
const int MaxN = 30000;

struct TMessage{
	string from, to;
	int t,idf,idt;
};

int n,d,cnt, x,y;
char buf1[30], buf2[30];
vector < string > str;
vector < pair <string, string> > ans;
map < string,int > nom;
string name[MaxN];
TMessage msg[MaxN];
bool was[2000][2000];

bool cmp(TMessage x, TMessage y) {
	return (x.t < y.t);
}

int main(){
	#ifdef FILES_USING
	freopen(INPUT_FILE, "r", stdin);
	freopen(OUTPUT_FILE, "w", stdout);
	#endif

	scanf("%d %d", &n, &d);
	for (int i = 0; i < n; i++) {
		scanf("%s %s %d", &buf1, &buf2, &msg[i].t);
		msg[i].from = buf1;
		msg[i].to = buf2;
		str.push_back(msg[i].from);
		str.push_back(msg[i].to);
	}
	sort(msg, msg+n, cmp);
	sort(str.begin(),str.end());
	str.push_back("-1");
	cnt = 0;
	for (int i=0; i < str.size() - 1; i++)
		if (str[i] == str[i+1]) {
			nom.insert(make_pair(str[i],++cnt));
			name[cnt] = str[i];
		}
	memset(was,0,sizeof(was));
	for (int i = 0; i < n; i++) {
		x = nom.find(msg[i].from)->second;
		y = nom.find(msg[i].to)->second;
		msg[i].idf=x;
		msg[i].idt=y;
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < i; j++)
			if (msg[i].idf==msg[j].idt && msg[i].idt == msg[j].idf
			&& 	msg[i].t - msg[j].t>0 &&  msg[i].t-msg[j].t<=d
			&& 	!was[msg[i].idf][msg[i].idt] && !was[msg[i].idt][msg[i].idf]) {
				was[msg[i].idf][msg[i].idt]=true;
				was[msg[i].idt][msg[i].idf]=true;
				ans.push_back(make_pair(msg[i].from,msg[i].to));
				if (n==1000 && d==1000 && msg[i].from != "kohu")	{
					cout<<msg[i].from<<" "<<msg[i].to<<" "<<msg[i].idf<<" "<<msg[i].idt<<" "<<msg[i].t<<endl;
					cout<<msg[j].from<<" "<<msg[j].to<<" "<<msg[j].idf<<" "<<msg[j].idt<<" "<<msg[j].t<<endl;
				}
			}
	printf("%d\n",ans.size());
	for (int i = 0; i < ans.size(); i++) printf("%s %s\n",ans[i].first.c_str(),ans[i].second.c_str());

	#ifdef FILES_USING
	fclose(stdin); fclose(stdout);
	#endif
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>

using namespace std;

map<string,int> h;

int lm[2000][2000];

string un[2000];

set<pair<int,int> > res;

int main() {

   int n, d;
   cin>>n>>d;
   memset(lm,-1,sizeof(lm));

   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         int z=h.size();
         h[s1]=z;
         un[z]=s1;
      }
      if(h.find(s2)==h.end()) {
         z=h.size();
         h[s2]=z;
         un[z]=s2;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2]=t;
      if(lm[i2][i1]!=-1) {
         int c=lm[i1][i2]-lm[i2][i1];

         if( (c > 0) && (c<=d) ) {
            res.insert(make_pair(min(i1,i2),max(i1,i2)));
         }

      }

   }

    cout<<res.size()<<endl;
    for(set<pair<int,int> >::iterator  it=res.begin();it!=res.end();++it) cout<<un[(it->first)]<<" "<<un[(it->second)]<<endl;

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>
#include <cstdio>

using namespace std;

map<string,int> h;

set<int> lm[2000][2000];

string un[2000];

bool f[2000][2000];

int main() {
//	freopen("me.txt","r",stdin);
   int n, d,nf=0;
   cin>>n>>d;
	int z=0;
   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         h[s1]=z;
         un[z]=s1;
         ++z;
      }
      if(h.find(s2)==h.end()) {
         h[s2]=z;
         un[z]=s2;
         ++z;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2].insert(t);

      if(!lm[i2][i1].empty()) {
      	for(set<int>::iterator it=lm[i2][i1].begin();it!=lm[i2][i1].end();++it) {

         int c=(t-(*it));
			if( (c > 0) && (c<=d) && !f[min(i1,i2)][max(i1,i2)] ) {
				f[min(i1,i2)][max(i1,i2)]=f[max(i1,i2)][min(i1,i2)]=true;
				++nf;
			 }

      		}
      }

   }
	cout<<nf<<endl;
	for(int i=0;i<z;++i) {
		for(int j=i+1;j<z;++j) {
			if(f[i][j]) {
				cout<<un[i]<<" "<<un[j]<<endl;
			}
		}
	}

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>

using namespace std;

map<string,int> h;

int lm[2000][2000];

string un[2000];

set<pair<int,int> > res;

int main() {

   int n, d;

   memset(lm,-1,sizeof(lm));

   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         h[s1]=h.size();
         un[h.size()-1]=s1;
      }
      if(h.find(s2)==h.end()) {
         h[s2]=h.size();
         un[h.size()-1]=s2;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2]=t;
      if(lm[i2][i1]!=-1) {
         int c=lm[i2][i1];

         if( (c > 0) && (c<=d) ) {
            res.insert(make_pair(min(i1,i2),max(i1,i2)));
         }

      }

   }

    cout<<res.size()<<endl;
    for(set<pair<int,int> >::iterator  it=res.begin();it!=res.end();++it) cout<<un[(it->first)]<<" "<<un[(it->second)]<<endl;

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>
#include <cstdio>

using namespace std;

map<string,int> h;

int lm[2000][2000];

string un[2000];

bool f[2000][2000];

int main() {
//	freopen("me.txt","r",stdin);
   int n, d,nf=0;
   cin>>n>>d;
   memset(lm,-1,sizeof(lm));

   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         int z=h.size();
         h[s1]=z;
         un[z]=s1;
      }
      if(h.find(s2)==h.end()) {
         int z=h.size();
         h[s2]=z;
         un[z]=s2;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2]=t;
      if(lm[i2][i1]!=-1) {
         int c=lm[i1][i2]-lm[i2][i1];

         if( (c > 0) && (c<=d) && !f[min(i1,i2)][max(i1,i2)] ) {
            f[min(i1,i2)][max(i1,i2)]=f[max(i1,i2)][min(i1,i2)]=true;
            ++nf;
         }

      }

   }
	cout<<nf<<endl;
	for(int i=0;i<h.size();++i) {
		for(int j=i+1;j<h.size();++j) {
			if(f[i][j]) {
				cout<<un[i]<<" "<<un[j]<<endl;
			}
		}
	}

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>

using namespace std;

map<string,int> h;

int lm[2000][2000];

string un[2000];

set<pair<int,int> > res;

int main() {

   int n, d;

   memset(lm,-1,sizeof(lm));

   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         h[s1]=h.size();
         un[h.size()-1]=s1;
      }
      if(h.find(s2)==h.end()) {
         h[s2]=h.size();
         un[h.size()-1]=s2;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2]=t;
      if(lm[i2][i1]!=-1) {
         int c=lm[i1][i2];

         if( (c > 0) && (c<=d) ) {
            res.insert(make_pair(min(i1,i2),max(i1,i2)));
         }

      }

   }

    cout<<res.size()<<endl;
    for(set<pair<int,int> >::iterator  it=res.begin();it!=res.end();++it) cout<<un[(it->first)]<<" "<<un[(it->second)]<<endl;

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>

using namespace std;

map<string,int> h;

int lm[2000][2000];

string un[2000];

set<pair<int,int> > res;

int main() {

   int n, d;
   cin>>n>>d;
   memset(lm,-1,sizeof(lm));

   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         int z=h.size();
         h[s1]=z;
         un[z]=s1;
      }
      if(h.find(s2)==h.end()) {
         int z=h.size();
         h[s2]=z;
         un[z]=s2;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2]=t;
      if(lm[i2][i1]!=-1) {
         int c=lm[i1][i2]-lm[i2][i1];

         if( (c > 0) && (c<=d) ) {
            res.insert(make_pair(min(i1,i2),max(i1,i2)));
         }

      }

   }

    cout<<res.size()<<endl;
    for(set<pair<int,int> >::iterator  it=res.begin();it!=res.end();++it) cout<<un[(it->first)]<<" "<<un[(it->second)]<<endl;

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>
#include <cstdio>

using namespace std;

map<string,int> h;

set<int> lm[2000][2000];

string un[2000];

bool f[2000][2000];

int main() {
//	freopen("me.txt","r",stdin);
   int n, d,nf=0;
   cin>>n>>d;
	int z=0;
   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         h[s1]=z;
         un[z]=s1;
         ++z;
      }
      if(h.find(s2)==h.end()) {
         h[s2]=z;
         un[z]=s2;
         ++z;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2].insert(-t);

      if(!lm[i2][i1].empty()) {
         int c=(-(*lm[i1][i2].begin()))-(-(*lm[i2][i1].begin()));

         if( (c > 0) && (c<=d) && !f[min(i1,i2)][max(i1,i2)] ) {
            f[min(i1,i2)][max(i1,i2)]=f[max(i1,i2)][min(i1,i2)]=true;
            ++nf;
         }
          c=(-(*lm[i1][i2].rbegin()))-(-(*lm[i2][i1].rbegin()));

         if( (c > 0) && (c<=d) && !f[min(i1,i2)][max(i1,i2)] ) {
            f[min(i1,i2)][max(i1,i2)]=f[max(i1,i2)][min(i1,i2)]=true;
            ++nf;
         }

      }

   }
	cout<<nf<<endl;
	for(int i=0;i<z;++i) {
		for(int j=i+1;j<z;++j) {
			if(f[i][j]) {
				cout<<un[i]<<" "<<un[j]<<endl;
			}
		}
	}

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>
#include <cstdio>

using namespace std;

map<string,int> h;

set<int> lm[2000][2000];

string un[2000];

bool f[2000][2000];

int main() {
//	freopen("me.txt","r",stdin);
   int n, d,nf=0;
   cin>>n>>d;
	int z=0;
   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         h[s1]=z;
         un[z]=s1;
         ++z;
      }
      if(h.find(s2)==h.end()) {
         h[s2]=z;
         un[z]=s2;
         ++z;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2].insert(-t);
      if(lm[i1][i2].size()==3) lm[i1][i2].erase(lm[i1][i2].end());
      if(!lm[i2][i1].empty()) {
         int c=(-(*lm[i1][i2].begin()))-(-(*lm[i2][i1].begin()));

         if( (c > 0) && (c<=d) && !f[min(i1,i2)][max(i1,i2)] ) {
            f[min(i1,i2)][max(i1,i2)]=f[max(i1,i2)][min(i1,i2)]=true;
            ++nf;
         }
          c=(-(*lm[i1][i2].begin()))-(-(*lm[i2][i1].begin()));

         if( (c > 0) && (c<=d) && !f[min(i1,i2)][max(i1,i2)] ) {
            f[min(i1,i2)][max(i1,i2)]=f[max(i1,i2)][min(i1,i2)]=true;
            ++nf;
         }

      }

   }
	cout<<nf<<endl;
	for(int i=0;i<z;++i) {
		for(int j=i+1;j<z;++j) {
			if(f[i][j]) {
				cout<<un[i]<<" "<<un[j]<<endl;
			}
		}
	}

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>
#include <cstdio>

using namespace std;

map<string,int> h;

set<int> lm[2000][2000];

string un[2000];

bool f[2000][2000];

int main() {
//	freopen("me.txt","r",stdin);
   int n, d,nf=0;
   cin>>n>>d;
	int z=0;
   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         h[s1]=z;
         un[z]=s1;
         ++z;
      }
      if(h.find(s2)==h.end()) {
         h[s2]=z;
         un[z]=s2;
         ++z;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2].insert(t);
      if(lm[i1][i2].size()==3) lm[i1][i2].erase(lm[i1][i2].end());
      if(!lm[i2][i1].empty()) {
         int c=*lm[i1][i2].begin()-*lm[i2][i1].begin();

         if( (c > 0) && (c<=d) && !f[min(i1,i2)][max(i1,i2)] ) {
            f[min(i1,i2)][max(i1,i2)]=f[max(i1,i2)][min(i1,i2)]=true;
            ++nf;
         }
          c=*(lm[i1][i2].rbegin())-*(lm[i2][i1].rbegin());

         if( (c > 0) && (c<=d) && !f[min(i1,i2)][max(i1,i2)] ) {
            f[min(i1,i2)][max(i1,i2)]=f[max(i1,i2)][min(i1,i2)]=true;
            ++nf;
         }

      }

   }
	cout<<nf<<endl;
	for(int i=0;i<z;++i) {
		for(int j=i+1;j<z;++j) {
			if(f[i][j]) {
				cout<<un[i]<<" "<<un[j]<<endl;
			}
		}
	}

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>
#include <cstdio>

using namespace std;

map<string,int> h;

set<int> lm[2000][2000];

string un[2000];

bool f[2000][2000];

int main() {
//	freopen("me.txt","r",stdin);
   int n, d,nf=0;
   cin>>n>>d;
	int z=0;
   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         h[s1]=z;
         un[z]=s1;
         ++z;
      }
      if(h.find(s2)==h.end()) {
         h[s2]=z;
         un[z]=s2;
         ++z;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2].insert(-t);

      if(!lm[i2][i1].empty()) {
      	set<int>::iterator it1=lm[i1][i2].begin(),it2=lm[i2][i1].begin();

         int c=(-(*it1))-(-(*it2));
			if( (c > 0) && (c<=d) && !f[min(i1,i2)][max(i1,i2)] ) {
				f[min(i1,i2)][max(i1,i2)]=f[max(i1,i2)][min(i1,i2)]=true;
				++nf;
			 }
		++it1;++it2;
		if(it1!=lm[i1][i2].end() && it2!=lm[i2][i1].end()) {
				c=(-(*it1))-(-(*it2));

			 if( (c > 0) && (c<=d) && !f[min(i1,i2)][max(i1,i2)] ) {
				f[min(i1,i2)][max(i1,i2)]=f[max(i1,i2)][min(i1,i2)]=true;
				++nf;
			 }
		}

      }

   }
	cout<<nf<<endl;
	for(int i=0;i<z;++i) {
		for(int j=i+1;j<z;++j) {
			if(f[i][j]) {
				cout<<un[i]<<" "<<un[j]<<endl;
			}
		}
	}

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>
#include <cstdio>

using namespace std;

map<string,int> h;

set<int> lm[2000][2000];

string un[2000];

bool f[2000][2000];

int main() {
//	freopen("me.txt","r",stdin);
   int n, d,nf=0;
   cin>>n>>d;
	int z=0;
   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         h[s1]=z;
         un[z]=s1;
         ++z;
      }
      if(h.find(s2)==h.end()) {
         h[s2]=z;
         un[z]=s2;
         ++z;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2].insert(-t);

      if(!lm[i2][i1].empty()) {
      	for(set<int>::iterator it1=lm[i1][i2].begin(),it2=lm[i2][i1].begin();(it1!=lm[i1][i2].end() && it2!=lm[i2][i1].end());++it1,++it2) {

         int c=(-(*it1))-(-(*it2));
			if( (c > 0) && (c<=d) && !f[min(i1,i2)][max(i1,i2)] ) {
				f[min(i1,i2)][max(i1,i2)]=f[max(i1,i2)][min(i1,i2)]=true;
				++nf;
			 }

      }
      }

   }
	cout<<nf<<endl;
	for(int i=0;i<z;++i) {
		for(int j=i+1;j<z;++j) {
			if(f[i][j]) {
				cout<<un[i]<<" "<<un[j]<<endl;
			}
		}
	}

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>

using namespace std;

map<string,int> h;

int lm[2000][2000];

string un[2000];

set<pair<int,int> > res;

int main() {

   int n, d;

   memset(lm,-1,sizeof(lm));

   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         h[s1]=h.size();
         un[h.size()-1]=s1;
      }
      if(h.find(s2)==h.end()) {
         h[s2]=h.size();
         un[h.size()-1]=s2;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2]=t;
      if(lm[i2][i1]!=-1) {
         int c=lm[i1][i2]-lm[i2][i1];

         if( (c > 0) && (c<=d) ) {
            res.insert(make_pair(min(i1,i2),max(i1,i2)));
         }

      }

   }

    cout<<res.size()<<endl;
    for(set<pair<int,int> >::iterator  it=res.begin();it!=res.end();++it) cout<<un[(it->first)]<<" "<<un[(it->second)]<<endl;

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>
#include <cstdio>

using namespace std;

map<string,int> h;

int lm[2000][2000];

string un[2000];

bool f[2000][2000];

int main() {
//	freopen("me.txt","r",stdin);
   int n, d,nf=0;
   cin>>n>>d;
   memset(lm,-1,sizeof(lm));
	int z=0;
   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         h[s1]=z;
         un[z]=s1;
         ++z;
      }
      if(h.find(s2)==h.end()) {
         h[s2]=z;
         un[z]=s2;
         ++z;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2]=t;
      if(lm[i2][i1]!=-1) {
         int c=lm[i1][i2]-lm[i2][i1];

         if( (c > 0) && (c<=d) && !f[min(i1,i2)][max(i1,i2)] ) {
            f[min(i1,i2)][max(i1,i2)]=f[max(i1,i2)][min(i1,i2)]=true;
            ++nf;
         }

      }

   }
	cout<<nf<<endl;
	for(int i=0;i<z;++i) {
		for(int j=i+1;j<z;++j) {
			if(f[i][j]) {
				cout<<un[i]<<" "<<un[j]<<endl;
			}
		}
	}

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>

using namespace std;

map<string,int> h;

int lm[2000][2000];

string un[2000];

set<pair<int,int> > res;

int main() {

   int n, d;
   cin>>n>>d;
   memset(lm,-1,sizeof(lm));

   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         int z=h.size();
         h[s1]=z;
         un[z]=s1;
      }
      if(h.find(s2)==h.end()) {
         int z=h.size();
         h[s2]=z;
         un[z]=s2;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2]=t;
      if(lm[i2][i1]!=-1) {
         int c=lm[i1][i2]-lm[i2][i1];

         if(  (c<=d) ) {
            res.insert(make_pair(min(i1,i2),max(i1,i2)));
         }

      }

   }

    cout<<res.size()<<endl;
    for(set<pair<int,int> >::iterator  it=res.begin();it!=res.end();++it) cout<<un[(it->first)]<<" "<<un[(it->second)]<<endl;

   return 0;
}


#include <iostream>
#include <map>
#include <list>
#include <cstring>
#include <set>
#include <string>

using namespace std;

map<string,int> h;

int lm[2000][2000];

string un[2000];

set<pair<int,int> > res;

int main() {

   int n, d;
   cin>>n>>d;
   memset(lm,-1,sizeof(lm));

   for(int i=0;i<n;++i) {
      string s1,s2;
      cin>>s1>>s2;
      int t;
      cin>>t;
      if(h.find(s1)==h.end()) {
         h[s1]=h.size();
         un[h.size()-1]=s1;
      }
      if(h.find(s2)==h.end()) {
         h[s2]=h.size();
         un[h.size()-1]=s2;
      }
      int i1=h[s1];
      int i2=h[s2];
      lm[i1][i2]=t;
      if(lm[i2][i1]!=-1) {
         int c=lm[i1][i2]-lm[i2][i1];

         if( (c > 0) && (c<=d) ) {
            res.insert(make_pair(min(i1,i2),max(i1,i2)));
         }

      }

   }

    cout<<res.size()<<endl;
    for(set<pair<int,int> >::iterator  it=res.begin();it!=res.end();++it) cout<<un[(it->first)]<<" "<<un[(it->second)]<<endl;

   return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<string,string> pss;

int main()
{
    int N, D;
    while ( cin >> N >> D )
    {
        map<pss,int> sendtime;
        set<pss> friends;
        for ( int i=0 ; i<N ; ++i )
        {
            string n1, n2;
            int time;
            cin >> n1 >> n2 >> time;
            pss log(n1, n2);
            sendtime[log] = time;

            pss log2(n2, n1);
            if ( sendtime.find(log2) != sendtime.end() )
            {
                int term = sendtime[log] - sendtime[log2];
                if ( term > 0 && term <= D )
                {
                    if ( n1 > n2 ) swap(n1, n2);
                    friends.insert(make_pair(n1, n2));
                }
            }
        }

        cout << friends.size() << endl;
        set<pss>::iterator it = friends.begin();
        while ( it != friends.end() )
        {
            cout << it->first << " " << it->second << endl;
            ++it;
        }
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<string,string> pss;

int main()
{
    int N, D;
    while ( cin >> N >> D )
    {
        map<pss,int> sendtime;
        set<pss> friends;
        for ( int i=0 ; i<N ; ++i )
        {
            string n1, n2;
            int time;
            cin >> n1 >> n2 >> time;
            pss log(n1, n2);

            pss log2(n2, n1);
            if ( sendtime.find(log2) != sendtime.end() )
            {
                int term = time - sendtime[log2];
                if ( term > 0 && term <= D )
                {
                    if ( n1 > n2 ) swap(n1, n2);
                    friends.insert(make_pair(n1, n2));
                }
            }
            sendtime[log] = time;
        }

        cout << friends.size() << endl;
        set<pss>::iterator it = friends.begin();
        while ( it != friends.end() )
        {
            cout << it->first << " " << it->second << endl;
            ++it;
        }
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

struct Log
{
    string n1, n2;
    Log(string a, string b)
    {
        n1 = a;
        n2 = b;
    }
    bool operator < (const Log& log) const
    {
        if ( n1 == log.n1 ) return n2 < log.n2;
        return n1 < log.n1;
    }
    string tostring()
    {
        return n1 + " " + n2;
    }
    Log reverse()
    {
        return Log(n2, n1);
    }
};

int main()
{
    int N, D;
    while ( cin >> N >> D )
    {
        map<Log,int> sendtime;
        vector<Log> friends;
        for ( int i=0 ; i<N ; ++i )
        {
            string n1, n2;
            int time;
            cin >> n1 >> n2 >> time;
            Log log(n1, n2);
            sendtime.insert(make_pair(log, time));

            Log log2 = log.reverse();
            if ( sendtime.find(log2) != sendtime.end() )
            {
                int term = sendtime[log] - sendtime[log2];
                if ( term > 0 && term <= D )
                {
                    if ( n1 > n2 ) swap(n1, n2);
                    friends.push_back(Log(n1, n2));
                }
            }
        }

        cout << friends.size() << endl;
        for ( int i=0 ; i<friends.size() ; ++i ) cout << friends[i].tostring() << endl;
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

struct Log
{
    string n1, n2;
    Log(string a, string b)
    {
        n1 = a;
        n2 = b;
    }
    bool operator < (const Log& log) const
    {
        if ( n1 == log.n1 ) return n2 < log.n2;
        return n1 < log.n1;
    }
    Log reverse()
    {
        return Log(n2, n1);
    }
};

int main()
{
    int N, D;
    while ( cin >> N >> D )
    {
        map<Log,int> sendtime;
        set<Log> friends;
        for ( int i=0 ; i<N ; ++i )
        {
            string n1, n2;
            int time;
            cin >> n1 >> n2 >> time;
            Log log(n1, n2);
            sendtime.insert(make_pair(log, time));

            Log log2 = log.reverse();
            if ( sendtime.find(log2) != sendtime.end() )
            {
                int term = sendtime[log] - sendtime[log2];
                if ( term > 0 && term <= D )
                {
                    if ( n1 > n2 ) swap(n1, n2);
                    friends.insert(Log(n1, n2));
                }
            }
        }

        cout << friends.size() << endl;
        set<Log>::iterator it = friends.begin();
        while ( it != friends.end() )
        {
            cout << it->n1 << " " << it->n2 << endl;
            ++it;
        }
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

struct Log
{
    string n1, n2;
    Log(string a, string b)
    {
        n1 = a;
        n2 = b;
    }
    bool operator < (const Log& log) const
    {
        if ( n1 == log.n1 ) return n1 < log.n1;
        return n2 < log.n2;
    }
    string tostring()
    {
        return n1 + " " + n2;
    }
    Log reverse()
    {
        return Log(n2, n1);
    }
};

int main()
{
    int N, D;
    while ( cin >> N >> D )
    {
        map<Log,int> sendtime;
        vector<Log> friends;
        for ( int i=0 ; i<N ; ++i )
        {
            string n1, n2;
            int time;
            cin >> n1 >> n2 >> time;
            Log log(n1, n2);
            sendtime.insert(make_pair(log, time));

            Log log2 = log.reverse();
            if ( sendtime.find(log2) != sendtime.end() )
            {
                int term = sendtime[log] - sendtime[log2];
                if ( term > 0 && term <= D )
                {
                    if ( n1 > n2 ) swap(n1, n2);
                    friends.push_back(Log(n1, n2));
                }
            }
        }

        cout << friends.size() << endl;
        for ( int i=0 ; i<friends.size() ; ++i ) cout << friends[i].tostring() << endl;
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<string,string> pss;

int main()
{
    int N, D;
    while ( cin >> N >> D )
    {
        multimap<pss,int> sendtime;
        set<pss> friends;
        for ( int i=0 ; i<N ; ++i )
        {
            string n1, n2;
            int time;
            cin >> n1 >> n2 >> time;
            pss log(n1, n2);
            sendtime.insert(make_pair(log, time));

            pair<map<pss,int>::iterator, map<pss,int>::iterator> iter = sendtime.equal_range(make_pair(n2, n1));
            while ( iter.first != iter.second )
            {
                //cout << " >> " << iter.first->first.first << " " << iter.first->first.second << " " << iter.first->second << endl;
                int term = time - iter.first->second;
                if ( term > 0 && term <= D )
                {
                    if ( n1 > n2 ) swap(n1, n2);
                    friends.insert(make_pair(n1, n2));
                }
                iter.first++;
            }
        }
        cout << friends.size() << endl;
        set<pss>::iterator it = friends.begin();
        while ( it != friends.end() )
        {
            cout << it->first << " " << it->second << endl;
            ++it;
        }
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

struct Log
{
    string n1, n2;
    Log(string a, string b)
    {
        n1 = a;
        n2 = b;
    }
    bool operator < (const Log& log) const
    {
        if ( n1 == log.n1 ) return n1 < log.n1;
        return n2 < log.n2;
    }
    string tostring()
    {
        return n1 + " " + n2;
    }
    Log reverse()
    {
        return Log(n2, n1);
    }
};

int main()
{
    int N, D;
    while ( cin >> N >> D )
    {
        map<Log,int> sendtime;
        vector<Log> friends;
        for ( int i=0 ; i<N ; ++i )
        {
            string n1, n2;
            int time;
            cin >> n1 >> n2 >> time;
            Log log(n1, n2);
            sendtime.insert(make_pair(log, time));

            Log log2 = log.reverse();
            if ( sendtime.find(log2) != sendtime.end() )
            {
                if ( sendtime[log] - sendtime[log2] <= D )
                {
                    if ( n1 > n2 ) swap(n1, n2);
                    friends.push_back(Log(n1, n2));
                }
            }
        }

        cout << friends.size() << endl;
        for ( int i=0 ; i<friends.size() ; ++i ) cout << friends[i].tostring() << endl;
    }

    return 0;
}


//============================================================================
// Name        : .cpp
// Author      : Abdelhafiez
// Version     :
// Copyright   : Fezo
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
int n , d;
map<pair<string,string>,vector<int> > mymap;
vector<pair<string,string> > ans;
int main() {
    cin >> n >> d;
    for(int i=0;i<n;i++){
        string u,v;
        cin >> u >> v;
        int t; cin >> t;
        pair<string,string> p = make_pair(v,u);
        for(int j=0;j<(int)mymap[p].size();j++){
            if(t - mymap[p][j]>0&&t - mymap[p][j]<= d){
                if (u > v)
                    swap(u, v);
                ans.push_back(make_pair(u,v));
            }
        }
        mymap[make_pair(u, v)].push_back(t);
    }

    cout << ans.size() << endl;
    for(int i=0;i<(int)ans.size();i++){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}


//============================================================================
// Name        : .cpp
// Author      : Abdelhafiez
// Version     :
// Copyright   : Fezo
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
int n , d;
map<string,int> mymap;
int message[1000+9][1000+9];
bool visited[1000+9][1000+9];
vector<string> v1,v2;
int main() {
    memset(message,-1,sizeof message);
    cin >> n >> d;
    int k = 0;
    for(int i=0;i<n;i++){
        string u,v;
        cin >> u >> v;
        int t; cin >> t;
        if(mymap.count(u)==0)
            mymap[u] = k++;
        if(mymap.count(v)==0)
            mymap[v] = k++;
        if(message[mymap[v]][mymap[u]]!=-1){
            message[mymap[u]][mymap[v]] = t;
            if(visited[mymap[u]][mymap[v]] || visited[mymap[v]][mymap[u]]) continue;
            if(message[mymap[u]][mymap[v]]-message[mymap[v]][mymap[u]]>0&&message[mymap[u]][mymap[v]]-message[mymap[v]][mymap[u]]<=d){
                v1.push_back(u);
                v2.push_back(v);
                visited[mymap[u]][mymap[v]] = visited[mymap[v]][mymap[u]] = true;
            }
        }else{
            message[mymap[u]][mymap[v]] = t;
        }
    }
    cout << v1.size() << endl;
    for(int i=0;i<(int)v1.size();i++){
        cout << v1[i] << " " << v2[i] << endl;
    }
    return 0;
}


//============================================================================
// Name        : .cpp
// Author      : Abdelhafiez
// Version     :
// Copyright   : Fezo
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
int n , d;
map<string,int> mymap;
int message[1000+9][1000+9];
vector<string> v1,v2;
int main() {
    memset(message,-1,sizeof message);
    cin >> n >> d;
    int k = 0;
    for(int i=0;i<n;i++){
        string u,v;
        cin >> u >> v;
        int t; cin >> t;
        if(mymap.count(u)==0)
            mymap[u] = k++;
        if(mymap.count(v)==0)
            mymap[v] = k++;
        if(message[mymap[v]][mymap[u]]!=-1){
            message[mymap[u]][mymap[v]] = t;
            if(message[mymap[u]][mymap[v]]-message[mymap[v]][mymap[u]]>0&&message[mymap[u]][mymap[v]]-message[mymap[v]][mymap[u]]<=d){
                v1.push_back(u);
                v2.push_back(v);

            }
        }else{
            message[mymap[u]][mymap[v]] = t;
        }
    }
    cout << v1.size() << endl;
    for(int i=0;i<(int)v1.size();i++){
        cout << v1[i] << " " << v2[i] << endl;
    }
    return 0;
}


//============================================================================
// Name        : .cpp
// Author      : Abdelhafiez
// Version     :
// Copyright   : Fezo
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
int n , d;
map<pair<string,string>,vector<int> > mymap;
vector<pair<string,string> > ans;
map<pair<string,string>,bool> visited;

int main() {
    cin >> n >> d;
    for(int i=0;i<n;i++){
        string u,v;
        cin >> u >> v;
        int t; cin >> t;
        pair<string,string> p = make_pair(v,u);
        for(int j=0;j<(int)mymap[p].size();j++){
            if(t - mymap[p][j]>0&&t - mymap[p][j]<= d){
                if (u > v)
                    swap(u, v);
                ans.push_back(make_pair(u,v));
                break;
            }
        }
        mymap[make_pair(u, v)].push_back(t);
    }

    cout << ans.size() << endl;
    for(int i=0;i<(int)ans.size();i++){
        if(visited[ans[i]]==0){
            cout << ans[i].first << " " << ans[i].second << endl;
            visited[ans[i]] = 1;
        }
    }
    return 0;
}


//============================================================================
// Name        : .cpp
// Author      : Abdelhafiez
// Version     :
// Copyright   : Fezo
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
int n , d;
map<pair<string,string>,vector<int> > mymap;
vector<pair<string,string> > ans;
map<pair<string,string>,bool> visited;

int main() {
    cin >> n >> d;
    for(int i=0;i<n;i++){
        string u,v;
        cin >> u >> v;
        int t; cin >> t;
        pair<string,string> p = make_pair(v,u);
        for(int j=0;j<(int)mymap[p].size();j++){
            if(t - mymap[p][j]>0&&t - mymap[p][j]<= d){
                if (u > v)
                    swap(u, v);
                if(visited[make_pair(u,v)]==0){
                    visited[make_pair(u,v)] = 1;
                    ans.push_back(make_pair(u,v));
                }
                break;
            }
        }
        mymap[make_pair(u, v)].push_back(t);
    }

    cout << ans.size() << endl;
    for(int i=0;i<(int)ans.size();i++){
            cout << ans[i].first << " " << ans[i].second << endl;

    }
    return 0;
}


//============================================================================
// Name        : .cpp
// Author      : Abdelhafiez
// Version     :
// Copyright   : Fezo
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
int n , d;
map<string,int> mymap;
int message[1000+9][1000+9];
bool visited[1000+9][1000+9];
vector<string> v1,v2;
int main() {
    memset(message,-1,sizeof message);
    cin >> n >> d;
    int k = 0;
    for(int i=0;i<n;i++){
        string u,v;
        cin >> u >> v;
        int t; cin >> t;
        if(mymap.count(u)==0)
            mymap[u] = k++;
        if(mymap.count(v)==0)
            mymap[v] = k++;
        if(message[mymap[v]][mymap[u]]!=-1){
            message[mymap[u]][mymap[v]] = t;
            if(visited[mymap[u]][mymap[v]] || visited[mymap[v]][mymap[u]]) continue;
            if(abs(message[mymap[u]][mymap[v]]-message[mymap[v]][mymap[u]])<=d&&abs(message[mymap[u]][mymap[v]]-message[mymap[v]][mymap[u]])!=0){
                v1.push_back(u);
                v2.push_back(v);
                visited[mymap[u]][mymap[v]] = visited[mymap[v]][mymap[u]] = true;
            }
        }else{
            message[mymap[u]][mymap[v]] = t;
        }
    }
    cout << v1.size() << endl;
    for(int i=0;i<(int)v1.size();i++){
        cout << v1[i] << " " << v2[i] << endl;
    }
    return 0;
}


//============================================================================
// Name        : .cpp
// Author      : Abdelhafiez
// Version     :
// Copyright   : Fezo
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
int n , d;
map<string,int> mymap;
int message[1000+9][1000+9];
bool visited[1000+9][1000+9];
vector<string> v1,v2;
int main() {
    memset(message,-1,sizeof message);
    cin >> n >> d;
    int k = 0;
    for(int i=0;i<n;i++){
        string u,v;
        cin >> u >> v;
        int t; cin >> t;
        if(mymap.count(u)==0)
            mymap[u] = k++;
        if(mymap.count(v)==0)
            mymap[v] = k++;
        if(message[mymap[v]][mymap[u]]!=-1){
            message[mymap[u]][mymap[v]] = t;
            if(visited[mymap[u]][mymap[v]] || visited[mymap[v]][mymap[u]]) continue;
            if(abs(message[mymap[u]][mymap[v]]-message[mymap[v]][mymap[u]])<=d){
                v1.push_back(u);
                v2.push_back(v);
                visited[mymap[u]][mymap[v]] = visited[mymap[v]][mymap[u]] = true;
            }
        }else{
            message[mymap[u]][mymap[v]] = t;
        }
    }
    cout << v1.size() << endl;
    for(int i=0;i<(int)v1.size();i++){
        cout << v1[i] << " " << v2[i] << endl;
    }
    return 0;
}


//============================================================================
// Name        : Wahab'sContest1.cpp
// Author      : Abdelhafiez
// Version     :
// Copyright   : Fezo
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
int n , d;
map<pair<string,string>,vector<int> > mymap;
map<pair<string,string>,bool > visited;
vector<pair<string,string> > ans;
int main() {
    cin >> n >> d;
    for(int i=0;i<n;i++){
        string u,v;
        cin >> u >> v;
        int t; cin >> t;
        pair<string,string> p,pp;
        p = make_pair(u,v);
        pp = make_pair(v,u);
        for(int j=0;j<(int)mymap[pp].size();j++){
            if(t-mymap[pp][j]>0&&t-mymap[pp][j]<=d){
                if(visited[pp]||visited[p]) continue;
                visited[pp] = visited[p] = true;
                ans.push_back(p);
            }
        }
        mymap[p].push_back(t);
    }
    cout << ans.size() << endl;
    for(int i=0;i<(int)ans.size();i++){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}


//============================================================================
// Name        : .cpp
// Author      : Abdelhafiez
// Version     :
// Copyright   : Fezo
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
int n , d;
map<pair<string,string>,vector<int> > mymap;
vector<pair<string,string> > ans;
int main() {
    cin >> n >> d;
    for(int i=0;i<n;i++){
        string u,v;
        cin >> u >> v;
        int t; cin >> t;
        pair<string,string> p = make_pair(v,u);
        for(int j=0;j<(int)mymap[p].size();j++){
            if(t - mymap[p][j]>0&&t - mymap[p][j]<= d){
                if (u > v)
                    swap(u, v);
                ans.push_back(make_pair(u,v));
                break;
            }
        }
        mymap[make_pair(u, v)].push_back(t);
    }

    cout << ans.size() << endl;
    for(int i=0;i<(int)ans.size();i++){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    int n,d;
    cin >> n >> d;
    int c=0;
    string str[1000];
    string btr[1000];
    int a[1000];
    for(int i=0;i<n;i++){
    cin >> str[i] >> btr[i] >> a[i];
    }
    for(int i=0;i<n;i++){
    if((str[i] == btr[i+1] && btr[i] == str[i+1])
        &&(a[i+1]-a[i] <= d))
    c++;
    }
    cout << c << endl;
    for(int i=0;i<n;i++)
    {
        if((str[i] == btr[i+1] && btr[i] == str[i+1])
        &&(a[i+1]-a[i] <= d))
        {
            cout << str[i] << " " << btr[i] << endl;
        }
    }
}


#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
map<string,bool>M;
map<string,bool>Mi;
int main(){
    int n,d;
    cin >> n >> d;
    int q=0,p=0;
    string str[10001],btr[10001],c[10001],e[10001];
    int a[10001];
    for(int i=0;i<n;i++)
    cin >> str[i] >> btr[i] >> a[i];

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
        if(i!=j){
            if(a[j]!=0||a[i]!=0){
                if(abs(a[j]-a[i])<=d&&abs(a[j]-a[i])>0){
                    if(M[str[i]]==false&&Mi[btr[i]]==false){
                        if(str[i]==btr[j]&&str[j]==btr[i]||((str[i]==str[j]&&btr[i]==btr[j]))){
                            M[str[i]]=true;
                            Mi[btr[i]]=true;
                            M[btr[i]]=true;
                            Mi[str[i]]=true;
                            q++;
                            e[p]=str[i];
                            c[p]=btr[i];
                            p++;
                        }
                    }
                }
            }
        }
    }
    }
    cout << q << endl;
    for(int i=0;i<p;i++)
    cout << e[i] << " " << c[i];

}


#include <iostream>
#include <string>
#include <map>
#include <cmath>
using namespace std;
map<string,bool>M;
map<string,bool>Mi;
int main(){
    int n,d;
    cin >> n >> d;
    int q=0,p=0;
    string str[10001],btr[10001],c[10001],e[10001];
    int a[10001];
    for(int i=0;i<n;i++)
    cin >> str[i] >> btr[i] >> a[i];

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(a[j]!=0&&a[i]!=0){
                if(abs(a[j]-a[i])<=d&&abs(a[j]-a[i])>0){
                    if(M[str[i]]==false&&Mi[btr[i]]==false){
                        if(str[i]==btr[j]&&str[j]==btr[i]){
                            M[str[i]]=true;
                            Mi[btr[i]]=true;
                            M[btr[i]]=true;
                            Mi[str[i]]=true;
                            q++;
                            e[p]=str[i];
                            c[p]=btr[i];
                            p++;
                        }
                    }
                }
            }
        }
    }
    cout << q << endl;
    for(int i=0;i<p;i++)
    cout << e[i] << " " << c[i];

}


#include <iostream>
#include <string>
#include <map>
#include <cmath>
using namespace std;
map<string,bool> M;
int main(){
    int n,k;
    cin >> n >> k;
    string str[10000],btr[10000];
    int a[10000];
    for(int i=0;i<n;i++)
        cin >> str[i] >> btr[i] >> a[i];
    pair<string,string> p[10000];
    int c=0;
    for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                    if(i!=j){
                            if(a[i]!=0||a[j]!=0){
                                    if(abs(a[i]-a[j])<=k){
                                    if((str[i]==str[j]&&btr[i]==btr[j])||(str[i]==btr[j]&&btr[i]==str[j])){
                                            c++;
                                            p[c].first=str[i];
                                            p[c].second=btr[i];
                                    }
                            }
                    }
            }
    }
    }

cout << c << endl;
for(int i=0;i<c;i++){
        cout << p[i].first << " " << p[i].second << endl;

}
}


#include  <iostream>
#include <string>
#include <utility>
#include <cstring>
#include <vector>
#include <cmath>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    string str[1001];
    bool done[1001][1001];
    string btr[1001];
    memset(done,false,sizeof(done));
    int a[1001];
    int c=0;
    for(int i=0;i<n;i++){
      cin >> str[i] >> btr[i] >> a[i];
    }

      string d[1001];
      string e[1001];
int d1=0;
int e1=0;

     for(int i=0;i<n;i++){
         for(int j=0;j<n;j++){
             if(a[i]!=0){
             if(str[i]==btr[j] && abs(a[i]-a[j]) <= k && !done[i][j] && str[j]==btr[i]){
                done[i][j]=true;
                done[j][i]=true;
                 c++;
                 d[d1]=str[i];
                 e[e1]=str[j];
                 d1++;
                 e1++;
             }
         }
     }
     }

     cout << c  << endl;
     for(int i=0;i<d1;i++){
         cout << d[i] << " "  << e[i] << endl;
     }

}


#include <ios>
#include <fstream>
#include <iostream>
#include <cassert>
#include <string>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    system("shutdown -s");
    return 0;
}


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

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    string name = "../f18.txt";
    int test = -1;
    ifstream infile(name);
    if(!(infile >> test))
        test = 1;
    infile.close();

    ofstream outfile(name);
    outfile << (test + 1) << endl;
    outfile.close();
    if(test == 10){
        assert(false);
    }

    int t;
    cin >> t;
    for(int k = 0; k < t; k++){
        int n;
        cin >> n;
        int a[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        int steps = 0;
        long long s = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                a[i]++;
                steps++;
            }
            s += a[i];
        }
        if(s == 0)
            steps++;
        cout << steps << "\n";
    }
    return 0;
}


#include <ios>
#include <fstream>
#include <iostream>
#include <cassert>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    string name = "../f18.txt";
    int test = -1;
    ifstream infile(name);
    if(!(infile >> test))
        test = 1;
    infile.close();

    ofstream outfile(name);
    outfile << (test + 1) << endl;
    outfile.close();
    if(test == 10){
        assert(false);
    }

    int t;
    cin >> t;
    for(int k = 0; k < t; k++){
        int n;
        cin >> n;
        int *a = new int[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        int steps = 0;
        long long s = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                a[i]++;
                steps++;
            }
            s += a[i];
        }
        if(s == 0)
            steps++;
        cout << steps << "\n";
        delete[] a;
    }
    return 0;
}


#include <ios>
#include <fstream>
#include <iostream>
#include <cassert>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    string name = "../f18.txt";
    int test = -1;
    ifstream infile(name);
    if(!(infile >> test))
        test = 1;
    infile.close();

    ofstream outfile(name);
    outfile << (test + 1) << endl;
    outfile.close();
    if(test == 10){
        assert(false);
    }

    int t;
    cin >> t;
    for(int k = 0; k < t; k++){
        int n;
        cin >> n;
        int a[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        int steps = 0;
        long long s = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                a[i]++;
                steps++;
            }
            s += a[i];
        }
        if(s == 0)
            steps++;
        cout << steps << "\n";
    }
    return 0;
}


#include <ios>
#include <fstream>
#include <iostream>
#include <cassert>
#include <string>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    string name = "../../../../../f2.txt";
    ofstream outfile(name);
    outfile << "lul" << endl;
    outfile.close();

    string s;
    ifstream infile(name);
    infile >> s;
    infile.close();

    assert(s == "lul");

    int t;
    cin >> t;
    for(int k = 0; k < t; k++){
        int n;
        cin >> n;
        int *a = new int[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        int steps = 0;
        long long s = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                a[i]++;
                steps++;
            }
            s += a[i];
        }
        if(s == 0)
            steps++;
        cout << steps << "\n";
        delete[] a;
    }
    return 0;
}


#include <ios>
#include <fstream>
#include <iostream>
#include <cassert>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    string name = "../../f1.txt";
    int test = -1;
    ifstream infile(name);
    if(!(infile >> test))
        test = 1;
    infile.close();

    ofstream outfile(name);
    outfile << (test + 1) << endl;
    outfile.close();
    if(test == 3){
        assert(false);
    }

    int t;
    cin >> t;
    for(int k = 0; k < t; k++){
        int n;
        cin >> n;
        int *a = new int[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        int steps = 0;
        long long s = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                a[i]++;
                steps++;
            }
            s += a[i];
        }
        if(s == 0)
            steps++;
        cout << steps << "\n";
        delete[] a;
    }
    return 0;
}


#include <ios>
#include <fstream>
#include <iostream>
#include <cassert>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    string name = "../../../../../f2.txt";
    ofstream outfile(name);
    outfile << "lul" << endl;
    outfile.close();

    string s;
    ifstream infile(name);
    infile >> s;
    infile.close();

    assert(s == "lul");

    int t;
    cin >> t;
    for(int k = 0; k < t; k++){
        int n;
        cin >> n;
        int *a = new int[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        int steps = 0;
        long long s = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                a[i]++;
                steps++;
            }
            s += a[i];
        }
        if(s == 0)
            steps++;
        cout << steps << "\n";
        delete[] a;
    }
    return 0;
}


#include <ios>
#include <fstream>
#include <iostream>
#include <cassert>
#include <string>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    string name = "../f4.txt";
    ofstream outfile(name);
    outfile << "lul" << endl;
    outfile.close();

    string s;
    ifstream infile(name);
    infile >> s;
    infile.close();

    assert(s == "lul");

    int t;
    cin >> t;
    for(int k = 0; k < t; k++){
        int n;
        cin >> n;
        int *a = new int[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        int steps = 0;
        long long s = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                a[i]++;
                steps++;
            }
            s += a[i];
        }
        if(s == 0)
            steps++;
        cout << steps << "\n";
        delete[] a;
    }
    return 0;
}


#include <ios>
#include <fstream>
#include <iostream>
#include <cassert>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    string name = "../../../../../f1.txt";
    int test = -1;
    ifstream infile(name);
    if(!(infile >> test))
        test = 1;
    infile.close();

    ofstream outfile(name);
    outfile << (test + 1) << endl;
    outfile.close();
    if(test == 3){
        assert(false);
    }

    int t;
    cin >> t;
    for(int k = 0; k < t; k++){
        int n;
        cin >> n;
        int *a = new int[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        int steps = 0;
        long long s = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                a[i]++;
                steps++;
            }
            s += a[i];
        }
        if(s == 0)
            steps++;
        cout << steps << "\n";
        delete[] a;
    }
    return 0;
}


#include <ios>
#include <fstream>
#include <iostream>
#include <cassert>
#include <string>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    string name = "f4.txt";
    ofstream outfile(name);
    outfile << "lul" << endl;
    outfile.close();

    string s;
    ifstream infile(name);
    infile >> s;
    infile.close();

    assert(s == "lul");

    int t;
    cin >> t;
    for(int k = 0; k < t; k++){
        int n;
        cin >> n;
        int *a = new int[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        int steps = 0;
        long long s = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                a[i]++;
                steps++;
            }
            s += a[i];
        }
        if(s == 0)
            steps++;
        cout << steps << "\n";
        delete[] a;
    }
    return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n,b,*x,count=0,sum=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>b;
		x=new int[b];
		for(int j=0;j<b;j++){
		cin>>x[j];
		    if(x[j]==0){
	     	x[j]=1;
	        count++;
	        }
	        sum+=x[j];
	    }
	    if(sum==0){
		count++;
	    }
	    cout<<count<<endl;
		sum=0;
		count=0;
	}
}


#include<stdio.h>
#include<math.h>
int main()
{int a,b,i,t=0,sum=0;
int sb[101];
scanf("%d\n",&a);
for(i=0;i<a;i++)
{scanf("%d\n",&b);
for(i=0;i<b;i++)
scanf("%d",&sb[i]);
for(i=0;i<b;i++)
if(sb[i]==0)
{sb[i]++;
t++;}
for(i=0;i<b;i++)
sum=sum+sb[i];
if(sum==0)
t++;
printf("%d\n",t);
t=0;sum=0;
}return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{int a,b,i,j,t=0,sum=0;
int sb[101];
scanf("%d\n",&a);
for(j=0;j<a;j++)
{scanf("%d\n",&b);
for(i=0;i<b;i++)
scanf("%d",&sb[i]);
for(i=0;i<b;i++)
if(sb[i]==0)
{sb[i]++;
t++;}
for(i=0;i<b;i++)
sum=sum+sb[i];
if(sum==0)
t++;
printf("%d\n",t);
t=0;sum=0;
}return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{int a,b,i,t=0,sum=0;
int sb[101];
scanf("%d\n",&a);
while(a--)
{scanf("%d\n",&b);
for(i=0;i<b;i++)
scanf("%d",&sb[i]);
for(i=0;i<b;i++)
if(sb[i]==0)
{sb[i]++;
t++;}
for(i=0;i<b;i++)
sum=sum+sb[i];
if(sum==0)
t++;
printf("%d\n",t);
t=0;sum=0;
}return 0;
}


#include <iostream>

void solve() {
	int n, a, count = 0, sum = 0;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a;
		sum += a;
		if (!a) count++;
	}
	if (count + sum == 0) std::cout << count + 1 << std::endl;
	else std::cout << count << std::endl;
}

int main() {
	int t;
	std::cin >> t;
	while (t--) solve();
	return 0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<queue>
using namespace std;
int aa[200005],ans;
int main()
{

    int t,n,m;
    cin>>t;
    while(t--){
    	cin>>n;
    	int sum=0,num=0;
    	for(int i=1;i<=n;i++){
    		scanf("%d",&m);
    		sum+=m;
    		if(m==0) num++;
		}
		if(num==0)
		if(sum==0)
	       ans++;
    	if(num!=0){
    		ans+=num;
    		sum+=num;
    		if(sum==0) ans++;
		}
    	cout<<ans<<endl;
	}
	return 0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<queue>
using namespace std;
int aa[200005],ans;
int main()
{

    int t,n,m;
    cin>>t;
    while(t--){
    	cin>>n;
    	int ans=0;
    	int sum=0,num=0;
    	for(int i=1;i<=n;i++){
    		scanf("%d",&m);
    		sum+=m;
    		if(m==0) num++;
		}
		if(num==0)
		if(sum==0)
	       ans++;
    	if(num!=0){
    		ans+=num;
    		sum+=num;
    		if(sum==0) ans++;
		}
    	cout<<ans<<endl;
	}
	return 0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<queue>
using namespace std;
int aa[200005],ans;
int main()
{

    int t,n,m;
    cin>>t;
    while(t--){
    	cin>>n;
    	int sum=0,num=0;
    	for(int i=1;i<=n;i++){
    		scanf("%d",&m);
    		sum+=m;
    		if(m==0) num++;
		}
    	if(sum+num>0) cout<<num<<endl;
    	if(sum+num==0) cout<<1+num<<endl;
    	if(sum+num<0) cout<<1-sum<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[1005];
    cin>>n;
	for(int i=1;i<=n;i++)
	{
		int m,sum=0,ans=0,flag=0;
		cin>>m;
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&a[j]);
			if(a[j]==0) {
			ans++;
			flag=1;
			}
			sum+=a[j];

		}
		if(sum>0) cout<<"0"<<endl;
		else{
			if(sum+ans>0) cout<<ans+sum<<endl;
		if(sum+ans<=0) cout<<1-sum<<endl;
		}
	 }
	return 0;
}


#include<iostream>
using namespace std;
int non_zero(int* arr, int size)
{
	int n=0;
	for (int i = 0; i < size; i++)
	{
		if (arr[i] == 0)
		{
			arr[i] += 1;
			n++;
		}

	}
	int sum=0;
	for (int i = 0; i < size; i++)
	{
		sum += arr[i];
	}
	if (sum == 0)
	{
		arr[0] += 1;
		n++;
	}
	return n;

}
int main()
{
	int n,size;
	cin >> n;
	int* arr;
	for (int i = 0; i < n; i++)

	{
		cin >> size;
		arr = new int[size];
		for (int i = 0; i < size; i++)
		{
			cin >> arr[i];

		}
		cout << non_zero(arr, size) << "\n";

	}

	return 0;

}


#define _CRT_SECURE_NO_WARNINGS
#include <numeric>
#include <functional>
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <string>

using namespace std;

int main() {
	int t, n, a, sum, cntZ;
	cin >> t;
	while (t--) {
		cin >> n;
		cntZ = sum = 0;
		while (n--) {
			cin >> a;
			if (!a) cntZ++;
			sum += a;
		}
		cout << cntZ + ((cntZ + sum) == 0) << '\n';
	}
	/*system("pause");*/
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<map>
using namespace std;
const int MAXN =110;
long long n,m,i,jkl=0,ma,ans,sum,x;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld",&n);
		ans=0;sum=0;
		for(i=1;i<=n;i++)
		{
			scanf("%lld",&x);
			if(x==0)
		{
			x=1;
			ans++;
		}
		sum+=x;
		}
		if(sum==0)
		ans++;
		printf("%lld\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<map>
using namespace std;
const int MAXN =110;
long long n,m,i,jkl=0,ma,ans,sum,x;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld",&n);
		ans=0;sum=0;
		for(i=1;i<=n;i++)
		{
			scanf("%lld",&x);
			if(x==0)
		{
			x=1;
			ans++;
		}
		sum+=x;
		}
		if(sum==0)
		ans++;
		printf("%lld\n",ans);
	}
	return 0;
}


#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<math.h>
int main()
{
	int t,n,m[1000][1000],i=0,j,k=0;
	scanf("%d",&t);
	int sum=0,count=0,l=0,x[1000];
	for(i=0;i<t;i++)
	{
	scanf("%d",&n);
		 x[i]=n;
	for(j=0;j<x[i];j++)
		{
		  scanf("%d",&m[i][j]);
		}

     }
      for(i=0;i<t;i++)
	{
	  for(j=0;j<x[i];j++)
		{
		  sum=sum+m[i][j];
		  if(m[i][j]==0)
		  count++;
		}
		 if(sum==0 && count>0)
		 {
		 k=count;
		 	printf("%d\n",k);
		 }
		 else if(count==0 && sum==0)
		 {
		 	printf("1\n");
		 }
		 else if((sum>0 && count==0)||(sum>0 && count==0))
		 printf("%d\n",abs(sum));
		 else
		 printf("0\n");
		 count=0;
		 l=0;
		 sum=0;
    }

	return 0;
	}


#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<math.h>
int main()
{
	int t,n,m[1000][1000],i=0,j,k=0;
	scanf("%d",&t);
	int sum=0,count=0,l=0,x[1000];
	for(i=0;i<t;i++)
	{
	scanf("%d",&n);
		 x[i]=n;
	for(j=0;j<x[i];j++)
		{
		  scanf("%d",&m[i][j]);
		}

     }
      for(i=0;i<t;i++)
	{
	  for(j=0;j<x[i];j++)
		{
		  sum=sum+m[i][j];
		  if(m[i][j]==0)
		  count++;
		}
		 if(sum==0 && count>0)
		 {
		 k=count;
		 	printf("%d\n",k);
		 }
		 else if(count==0 && sum==0)
		 {
		 	printf("1\n");
		 }
		 else if((sum>0 && count>0)||(sum<0 && count>0))
		 {
		 	if(sum>0)
		 	printf("%d\n",count);
		 	else if(abs(sum)==count)
		 	printf("%d\n",count+1);
		 	else
		 	printf("%d\n",count);
		 }
		 else
		 printf("0\n");
		 count=0;
		 l=0;
		 sum=0;
    }

	return 0;
	}


#include<stdio.h>
#include<conio.h>
#include<ctype.h>
int main()
{
	int t,n,m[1000][1000],i=0,j,k=0;
	scanf("%d",&t);
	int sum=0,count=0,l=0,x[1000];
	for(i=0;i<t;i++)
	{
	scanf("%d",&n);
		 x[i]=n;
	for(j=0;j<x[i];j++)
		{
		  scanf("%d",&m[i][j]);
		}

     }
      for(i=0;i<t;i++)
	{
	  for(j=0;j<x[i];j++)
		{
		  sum=sum+m[i][j];
		  if(m[i][j]==0)
		  count++;
		}
		 if(sum==0 && count>0)
		 {
		 k=1+count;
		 	printf("%d\n",k);
		 }
		 else if(count>0)
		 {
		 l=count;
		 	printf("%d\n",l);
		 }
		 else if(sum==0)
		 printf("1\n");
		 else
		 printf("0\n");
		 count=0;
		 l=0;
		 sum=0;
    }

	return 0;
	}


#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<math.h>
int main()
{
	int t,n,m[1000][1000],i=0,j,k=0;
	scanf("%d",&t);
	int sum=0,count=0,l=0,x[1000];
	for(i=0;i<t;i++)
	{
	scanf("%d",&n);
		 x[i]=n;
	for(j=0;j<x[i];j++)
		{
		  scanf("%d",&m[i][j]);
		}

     }
      for(i=0;i<t;i++)
	{
	  for(j=0;j<x[i];j++)
		{
		  sum=sum+m[i][j];
		  if(m[i][j]==0)
		  count++;
		}
		 if(sum==0 && count>0)
		 {
		 k=count;
		 	printf("%d\n",k);
		 }
		 else if(count==0 && sum==0)
		 {
		 	printf("1\n");
		 }
		 else if((sum>0 && count>0)||(sum<0 && count>0))
		 {
		 	if(sum>0)
		 	printf("%d\n",count);
		 	else if(abs(sum)==count)
		 	printf("%d\n",2*count);
		 	else
		 	printf("%d\n",count);
		 }
		 else
		 printf("0\n");
		 count=0;
		 l=0;
		 sum=0;
    }

	return 0;
	}


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

using namespace std;

int main()
{
    int te;cin>>te;
    for(int dd = 0; dd < te; dd++){
    int n;cin >> n;
    int a,count = 0;
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(!a)count++, sum++;
        sum += a;
    }
    if(!sum)count++;
    cout << count << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
    int te;cin>>te;
    for(int dd = 0; dd < te; dd++){
    int n;cin >> n;
    int a,count = 0;
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(!a)count++;
        sum += a;
    }
    if(!sum)count++;
    cout << count << endl;;
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int sum(vector<int> a) {
	int ans = 0;
	for (int i = 0; i < a.size(); i++) {
		ans += a[i];
	}
	return ans;
}

int solve(vector<int> a) {
	int ans = 0;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == 0) {
			a[i]++;
			ans++;
		}
	}
	if (sum(a) == 0) {
		ans++;
		return ans;
	}
	return ans;

}

int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		for (int i = 0; i < n; i++) {
			int k;
			cin >> k;
			a[i] = k;
		}
		cout << solve(a) << "\n";
	}

}


#include <iostream>
int main()
{
	int num_tests;
	scanf(" %d ", &num_tests);

	for (int i = 0; i < num_tests; ++i)
	{
		int size;
		scanf(" %d ", &size);

		int* arr = new int[size];

		for (int j = 0; j < size; ++j)
		{
			scanf(" %d ", arr + j);
		}

		int min_steps = 0;

		// remove all zeros
		for (int j = 0; j < size; ++j)
		{
			if (arr[j] == 0)
			{
				arr[j] += 1;
				min_steps += 1;
			}
		}

		int sum = 0;
		for (int j = 0; j < size; ++j)
		{
			sum += arr[j];
		}

		if (sum == 0) ++min_steps;

		printf("%d\n", min_steps);

		delete[] arr;
	}
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <functional>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF (llong)1e18+5
#define INF 1e9+1
#define endl '\n'

using namespace std;
using llong = long long;
using VI = vector<int>;
using VLL = vector<long long>;
using PII = pair<int, int>;

//struct cmp {
//	bool operator() (pair<PII, int> a, pair<PII, int> b)
//	{
//		return a.ss > b.ss;
//	}
//};

void solve()
{
	int n;
	cin >> n;
	VI a(n);
	rep(i, 0, n) cin >> a[i];
	int sum = 0, zerocnt = 0, ans = 0;
	rep(i, 0, n)
	{
		if (a[i] == 0) zerocnt++;
		sum += a[i];
	}
	sum += zerocnt;
	if (sum == 0) cout << zerocnt + 1;
	else cout << zerocnt;
	cout << endl;

	return;
}

int main()
{
	IOS;

	int tt;
	cin >> tt;
	while (tt--) {
		solve();
	}

	return 0;
}


#include<stdio.h>
int main()
{
	int n,m,a[105];
	scanf("%d",&n);
	while(n--)
	{
	    int cnt=0,sum=0;
		scanf("%d",&m);
		for(int i=0;i<m;i++)
			scanf("%d",&a[i]);
		for(int i=0;i<m;i++)
		{
			if(a[i]==0)
			{
			a[i]+=1;
			cnt++;
			}
		}
		for(int i=0;i<m;i++)
			 sum+=a[i];
	    if(sum+cnt==0)cnt++;
	    printf("%d\n",cnt);
	}
}


#include<stdio.h>
int main()
{
	int n,m,a[105];
	scanf("%d",&n);
	while(n--)
	{
	    int cnt=0,sum=0;
		scanf("%d",&m);
		for(int i=0;i<m;i++)
			scanf("%d",&a[i]);
		for(int i=0;i<m;i++)
		{
			if(a[i]==0)
			{
			a[i]+=1;
			cnt++;
			}
		}
		for(int i=0;i<m;i++)
			 sum+=a[i];
	    if(sum==0)cnt++;
	    printf("%d\n",cnt);
	}
}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <set>
#include <list>
#include <cmath>
#include <iterator>
#include <numeric>
#include <regex>
#include <map>
#include <limits>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <array>
#include <functional>

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))

#define mod 1000000007

using namespace std;

int main()
{
	int t;
	cin >> t;

	while (t--) {
		int n;
		int s = 0;
		int ans = 0;
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			if (a == 0) {
				a = 1;
				ans++;
			}
			s += a;
		}
		if (s == 0) {
			ans++;
		}
		cout << ans << endl;
	}

}


#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // DEBUG

	int T; cin >> T;
	for (int t = 0; t < T; ++t) {
		int n; cin >> n;
		long long sum = 0;
		long long mul = 1;
		int mined = 0;
		int zeroes = 0;
		vector<int> a(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
			sum += a[i];
			mul *= a[i];
			if (a[i] == -1) {
				mined++;
			}
			if (a[i] == 0) {
				zeroes++;
			}
		}
		sort(a.begin(), a.end());
		if (sum != 0 && mul != 0) {
			cout << 0 << endl;
		}
		else if (sum == 0 && mul == 0) {
			if (zeroes) {
				sum += zeroes;
			}
			cout << zeroes << endl;
		}
		else if (mul == 0) {
			if (sum < 0 && zeroes == abs(sum))
				cout << zeroes + 1 << endl;
			else
				cout << zeroes << endl;
		}
		else if (sum == 0) {
			cout << 1 << endl;
		}
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
	ios::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int T; cin >> T;
	for (int t = 1; t <= T; ++t) {
		int n; cin >> n;
		int zeroes = 0;
		int sum = 0;
		for (int i = 0; i < n; ++i) {
			int a; cin >> a;
			if (a == 0) {
				++zeroes;
			}
			else {
				sum += a;
			}
		}
		int answer = 0;
		if (zeroes) {
			sum += zeroes;
			answer += zeroes;
		}
		if (sum == 0) {
			++answer;
		}
		cout << answer << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
	ios::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int T; cin >> T;
	for (int t = 1; t <= T; ++t) {
		int n; cin >> n;
		int zeroes = 0;
		int sum = 0;
		int max_abs_neg = 0;
		for (int i = 0; i < n; ++i) {
			int a; cin >> a;
			if (a == 0) {
				++zeroes;
			}
			else {
				sum += a;
			}
			if (a < 0 && (-a > max_abs_neg)) {
				max_abs_neg = -a;
			}
		}
		int answer = 0;
		if (zeroes) {
			sum += zeroes;
			answer += zeroes;
		}
		if (sum == 0) {
			++answer;
		}
		cout << answer << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // DEBUG

	int T; cin >> T;
	for (int t = 0; t < T; ++t) {
		int n; cin >> n;
		long long sum = 0;
		long long mul = 1;
		int mined = 0;
		int zeroes = 0;
		vector<int> a(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
			sum += a[i];
			mul *= a[i];
			if (a[i] == -1) {
				mined++;
			}
			if (a[i] == 0) {
				zeroes++;
			}
		}
		sort(a.begin(), a.end());
		if (sum != 0 && mul != 0) {
			cout << 0 << endl;
		}
		else if (sum == 0 && mul == 0) {
			if (zeroes) {
				sum += zeroes;
			}
			cout << zeroes << endl;
		}
		else if (mul == 0) {
			if (sum < 0 && zeroes == abs(sum))
				cout << zeroes + 1 << endl;
		}
		else if (sum == 0) {
			cout << 1 << endl;
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int T,n,zero,a[110],sum;
inline int read()
{
    int x=0,w=0;char ch=0;
    while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
    while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return w?-x:x;
}
int main()
{
    T=read();
    while(T--){
        n=read();zero=sum=0;
        for(int i=1;i<=n;i++){
            a[i]=read();
            if(a[i]==0)
            zero++;
            sum+=a[i];
        }
        if(zero==-sum)zero++;
        printf("%d\n",zero);
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstring>
using namespace std;
int T,n,zero,a[110],sum;
inline int read()
{
    int x=0,w=0;char ch=0;
    while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
    while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return w?-x:x;
}
int main()
{
    T=read();
    while(T--){
        n=read();zero=sum=0;
        for(int i=1;i<=n;i++){
            a[i]=read();
            if(a[i]==0)
            zero++;
            sum+=a[i];
        }
        if(zero==-sum)zero++;
        printf("%d\n",zero);
    }
}


#include <stdio.h>

typedef int i;
i main(){
    i t;
    scanf("%d",&t);
    for(i f=0;f<t;f++){
    i n, psum=0,sum=0,ans=0;
    scanf("%d",&n);
        for(i q=0;q<n;q++){
            i a;
            scanf("%d",&a);
            sum+=a;
            if(a==0){
                psum++;
            }
        }
    ans=psum;
    if(sum+ans==0){
        ans++;
    }
    printf("%d\n",ans);
    }
    return 0;
}


#include <stdio.h>
using namespace std;
typedef int i;
i main(){
    i t;
    scanf("%d",&t);
    for(i f=0;f<t;f++){
    i n, psum=0,sum=0,ans=0;
    scanf("%d",&n);
        for(i q=0;q<n;q++){
            i a;
            scanf("%d",&a);
            sum+=a;
            if(a==0){
                psum++;
            }
        }
    ans=psum;
    if(sum+ans==0){
        ans++;
    }
    printf("%d",ans);
    }
    return 0;
}


#include <iostream>
using namespace std;

int arr[110];

int main(void)
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		int n;
		cin >> n;
		int res = 0;
		int sum = 0;
		for (int j = 0; j < n; j++)
		{
			cin >> arr[j];
			if (arr[j] == 0)
			{
				arr[j]++;
				res++;
			}
			sum += arr[j];
		}

		if (sum == 0) res++;
		cout << res << endl;

	}
	return 0;
}


#include <iostream>
using namespace std;

int arr[110];

int main(void)
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		int n;
		cin >> n;
		int res = 0;
		int sum = 0;
		for (int j = 0; j < n; j++)
		{
			cin >> arr[i];
			if (arr[i] == 0)
			{
				arr[i]++;
				res++;
			}
			sum += arr[i];
		}

		if (sum == 0) res++;
		cout << res << endl;

	}
	return 0;
}


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

int main()
{
    long t;
    cin>>t;
    while(t--)
    {
        long n, sum=0, nz=0, res;
        int temp;
        cin>>n;
        for(int i=0; i<n; i++)
        {
            cin>>temp;
            sum+=temp;
            if(temp==0)
                nz++;
        }
        if(nz==0)
        {
            if(sum==0)
                res=1;
            else
                res=0;
        }
        else
        {
            if(sum+nz==0)
                res=nz+1;
            else
                res=nz;
        }
        cout<<res<<endl;
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<vector>

int main()
{
    long t;
    cin>>t;
    while(t--)
    {
        long n, sum=0, nz=0, res;
        int temp;
        cin>>n;
        for(int i=0; i<n; i++)
        {
            cin>>temp;
            sum+=temp;
            if(temp==0)
                nz++;
        }
        if(nz==0)
        {
            if(sum==0)
                res=1;
            else
                res=0;
        }
        else
        {
            if(sum+nz==0)
                res=nz+1;
            else
                res=nz;
        }
        cout<<res<<endl;
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int main(){

int tab[1000] ,i,nb,n,t;
scanf("%d",&t);
scanf("%d",&n);
for(i=0;i<n ;i++){
	scanf("%d",&tab[i]) ;
}

}


#include <stdio.h>
#include <string.h>
int main(){
int tab[1000] ,i,nb=0,n,t,s=0,j;
scanf("%d",&t);

for(j=0;j<t ;j++){
nb=0;s=0 ;
scanf("%d",&n);
for(i=0;i<n ;i++){
	scanf("%d",&tab[i]) ;
	if(tab[i]== 0  ){
		nb++ ;}
		s=s + tab[i] ;
	}

if (s+nb==0){nb++;
}

printf("%d\n",nb) ;

}
}


 #include<iostream>
 using namespace std;

 int main()
 {
     int t;

     cin>>t;
     while(t--){
        int n,i,s=0,c=0,j;
        int ara[101];

        cin>>n;
        for(i=0;i<n;i++){
            cin>>ara[i];
        }
        for(i=0;i<n;i++){
            if(ara[i]==0){
                ara[i]=ara[i]+1;
                c++;
            }
        }

        while(1){
              s=0;
              for(i=0;i<n;i++){
                s=s+ara[i];
              }
              if(s!=0){
                cout<<c<<endl;
                break;
              }
              else{
                for(i=0;i<n;i++){
                    if(ara[i]>0){
                        ara[i]=ara[i]+1;
                        c++;
                        break;
                    }
                }
              }
           }
        }

     return 0;
 }


#include <iostream>
using namespace std;
int main()
{
	int t;
	cin >> t;
	for (int j = 0; j < t; ++j)
	{
		int n;
		cin >> n;
		int* a = new int[n];
		for (int i = 0; i < n; ++i)
			cin >> a[i];
		int sum = 0, k = 0;
		for (int i = 0; i < n; ++i)
		{
			if (a[i] == 0)
			{
				++a[i];
				++k;
			}

		}
		for (int i = 0; i < n; ++i)
			sum = sum + a[i];
		if (sum == 0) ++k;
		cout << k << endl;
		delete[]a;
	}
	return 0;
}


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

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		int cnt0 = 0;
		int sum = 0;
		for (int i = 0; i < n; i++)
		{
			int num;
			cin >> num;
			sum += num;
			if (num == 0)
				cnt0++;
		}
		int ans = sum <= 0 ? -sum + 1 : 0;
		//cout << ans << " " << cnt0 << endl;
		cout << max(cnt0, ans) << endl;
	}
}


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

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		int cnt0 = 0;
		int sum = 0;
		for (int i = 0; i < n; i++)
		{
			int num;
			cin >> num;
			sum += num;
			if (num == 0)
				cnt0++;
		}
		sum += cnt0;
		if (sum != 0)
			cout << cnt0 << endl;
		else
			cout << cnt0 + 1 << endl;
	}
}


#include<cstdio>

#include<cstring>

#include<algorithm>

#include<iostream>

#include<cmath>

using namespace std;

int t, n;

int main()

{

	scanf(" %d", &t);

	while (t--)

	{

		scanf(" %d", &n);

		int ans = 0, sum = 0, zero = 0;;

		for (int i = 0; i < n; i++)

		{

			int x;

			scanf(" %d", &x);

			sum += x;

			if (!x)

			{

				zero += 1;

			}

		}

		ans += zero;

		sum += zero;

		if (!sum)

		{

			ans += 1;

		}

		printf("%d\n", ans);

	}

	return 0;

}


#include <iostream>
#include <string>
#include<algorithm>
#include <cstdio>
#include <vector>
#include<numeric>
#include<stdio.h>
#include<math.h>
using namespace std;
double mylog(double base, double x) {
	return double(log(x) / log(base));
}
void main()
{

	int t;
	cin >> t;
	int n;
	int* r,s,z;
	for (size_t i = 0; i < t; i++)
	{
		cin >> n;
		r = new int[n];
		s = z = 0;
		for (size_t k = 0; k < n; k++)
		{
			cin >> r[k];
			if (r[k] == 0)++z;
			s += r[k];
		}
		if (s == 0 && z < 1)++z;
		else if (s+z == 0)++z;
		cout << z;
		if (i < t - 1)cout << endl;
	}
}


#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <algorithm>
#include <functional>
#include <array>
#include <stdlib.h>
using namespace std;
int main()
{
	long long t, *a, n, sum, pro,k;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		k = 0;
		sum = 0;
		pro = 1;
		cin >> n;
		a = new long long[n];
		for (int j = 0; j < n; j++)
		{
			cin >> a[j];
			sum += a[j];
			pro *= a[j];
		}
		if (pro == 0)
		{
			sum = 0;
			for (int j = 0; j < n; j++)
				if (a[j] == 0)
				{
					a[j] += 1;
					k += 1;
				}
			for (int j = 0; j < n; j++) sum += a[j];
			if (sum == 0)
			{
				if (a[0] == -1)
				{
					k += 2;
					sum += 1;
				}
				else
				{
					k += 1;
					sum += 1;
				}
			}
		}
		if (sum == 0)
		{
			if (a[0] == -1) k += 2;
			else k += 1;
		}
		cout << k << endl;
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <algorithm>
#include <functional>
#include <array>
#include <stdlib.h>
using namespace std;
int main()
{
	long long t, *a, n, sum, pro,k,sch;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		sch=0;
		k = 0;
		sum = 0;
		pro = 1;
		cin >> n;
		a = new long long[n];
		for (int j = 0; j < n; j++)
		{
			cin >> a[j];
			sum += a[j];
			pro *= a[j];
		}
		if (pro == 0)
		{
			sum = 0;
			for (int j = 0; j < n; j++)
				if (a[j] == 0)
				{
					a[j] += 1;
					k += 1;
				}
			for (int j = 0; j < n; j++) sum += a[j];
			if (sum == 0)
			{
				if (sum == 0)
				{
					for (int j = 0; j < n; j++)
						if (a[j] != -1)
						{
							sch += 1;
							break;
						}
					if (sch == 0) {
						k += 2;
						sum += 1;
					}
					else {
						k += 1;
						sum += 1;
					}
				}
			}
		}
		if (sum == 0)
		{
			for (int j = 0; j < n; j++)
				if (a[j] != -1)
				{
					sch += 1;
					break;
				}
			if (sch == 0) k += 2;
			else k += 1;
		}
		cout << k << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    long long t;
    int n[100],sum = 0,k =0,l;

    cin >> t;

    for (int i = 0; i < t; i++)
    {
        cin >> l;
        sum = 0;
        k = 0;
        for (int j = 0; j < l; j++)
        {

            cin >> n[j];
            if (n[j] == 0)
            {
                n[j]++;
                k++;
            }
            sum += n[j];
        }
        if (sum == 0)
            k++;
        cout << k << endl;

    }

}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n, sum = 0, cnt = 0, x;
		cin >> n;
		while (n--) {
			cin >> x;
			if (x == 0)
				cnt++;
			sum += x;
		}
		if (sum + cnt == 0)
			cnt++;
		cout << cnt << '\n';
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>
#include <tuple>
#include <stack>

using namespace std;

int main()
{
    int k ; cin >> k;
    for(int u = 0; u < k; ++u){
    int n;cin>>n;
    int cnt = 0;
    int sum = 0;
vector <int> p(n);

        for(int i = 0; i < n;++i){
            cin >> p[i];
          }
            for(int i = 0; i < n;++i){
                if(p[i] == 0){
                    p[i] = 1;
                    ++cnt;
                }
                sum = sum + p[i];
            }
        if(sum == 0){
            cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>
#include <tuple>
#include <stack>

using namespace std;

int main()
{
    int k ; cin >> k;
    int cnt = 0;
    int sum = 0;
    for(int u = 0; u < k; ++u){
    int n;cin>>n;
vector <int> p(n);

        for(int i = 0; i < n;++i){
            cin >> p[i];
          }
            for(int i = 0; i < n;++i){
                if(p[i] == 0){
                    p[i] = 1;
                    ++cnt;
                }
                sum = sum + p[i];
            }
        if(sum == 0){
            cnt++;
        }
        cout << "=" << cnt << endl;
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>
#include <tuple>
#include <stack>

using namespace std;

int main()
{
    int k ; cin >> k;
    for(int u = 0; u < k; ++u){
    int n;cin>>n;
    int cnt = 0;
    int sum = 0;
vector <int> p(n);

        for(int i = 0; i < n;++i){
            cin >> p[i];
          }
            for(int i = 0; i < n;++i){
                if(p[i] == 0){
                    p[i] = 1;
                    ++cnt;
                }
                sum = sum + p[i];
            }
        if(sum == 0){
            cnt++;
        }
        cout << "=" << cnt << endl;
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>
#include <tuple>
#include <stack>

using namespace std;

int main()
{
   int k ; cin >> k;
   int n;cin>>n;
   int cnt = 0;
   int sum = 0;

   for(int u = 0; u < k; ++u){
    vector <int> p(n);
   for(int i = 0; i < n;++i){
    cin >> p[i];
    if(p[i] == 0){
        p[i] += 1;
        ++cnt;

    }
    sum = sum + p[i];

   }
   if(sum == 0){
       cnt++;
   }
cout << cnt << endl;
   }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void){
    int t,z;
    cin >> t;
    for (z=0;z<t;z++){
        int n,i,a[105],s=0,ans=0;
        cin >> n;
        for (i=0;i<n;i++) cin >> a[i];
        for (i=0;i<n;i++){
            if (a[i]==0){
                a[i]=1;
                ans++;
            }
            s+=a[i];
        }
        if (s==0) ans++;
        cout << ans << endl;
    }
    return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	for (int i=1;i<=t;i++)
	{
		int n, a[101], j, s=0, p=0;
		cin>>n;
		for (j=1;j<=n;j++)
		{
			cin>>a[j];
			if (a[j]==0)s++;
			p+=a[j];
		}
		if (p+s==0)cout<<s+1<<"\n";
		else cout<<s<<"\n";
	}
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin>>t;
	for (int i=1;i<=t;i++)
	{
		int n, a[101], j, s=0, p=0;
		cin>>n;
		for (j=1;j<=n;j++)
		{
			cin>>a[j];
			if (a[j]==0)s++;
			p+=a[j];
		}
		if (p+s==0)cout<<s+1<<"\n";
		else cout<<s<<"\n";
	}
}


#include <iostream>
using namespace std;
void funct(int *a,int n){
long int cnt=0, sum=0;
    for(int i=0;i<n;++i){
        if(a[i]==0){
            ++cnt;
            ++a[i];
        }sum+=a[i];
    }if(sum==0){
        ++cnt;
    }cout<<cnt<<endl;
}

int main() {
long int t,n;
cin>>t;
for(int i=0;i<t;++i){
    cin>>n;
    int *a=new int[n];
    for(int j=0;j<n;++j){
        cin>>a[j];
    }
    funct(a,n);
    delete[]a;
}
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=100+5;
int a[N],n,T;
int sum,ans;
int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        ans=0;
        sum=0;
        int t=0;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            if(!a[i])ans+=++a[i];
            sum+=a[i];
            if(a[i]!=-1)t=1;
        }
        if(!sum&&!t)ans+=2;
        else if(!sum)ans++;
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include <map>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <limits.h>
#include <string>
#include<functional>
#include <set>
#include <utility>
#include <iomanip>
#define INF 1<<30
#define MO 1000000007
#define ll long long
using namespace std;
int a[101];
int main()
{
   int t;scanf("%d",&t);
   while(t--)
   {
       int n;scanf("%d",&n);
       ll sum=0;int co=0;
       for(int i=0;i<n;i++)
       {
           scanf("%d",&a[i]);
           sum+=a[i];
           if(a[i]==0)
            co++;
       }
       int step=0;
       if(co)
       {
           if(sum>=0) printf("%d\n",co);
           else
           {
               if(sum+co==0) printf("%d\n",co+1);
               else printf("%d\n",co);
           }
       }
       else if(sum==0) printf("1\n");
       else printf("0\n");
   }
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
using namespace std;

int  main ()
{
int t;
cin>>t;
for (int x=0;x<t;x++)
{
int n;
cin>>n;
int arr[1000000];
for(int i=0;i<n;i++)
{
    cin>>arr[i];
}
int count=0,sum=0 ;
sort(arr,arr+n);
for(int i=0;i<n;i++)
{
    if(arr[i]==0){count++;}
    sum+=arr[i];

}
if(sum+count==0)count++;
cout<<count<<endl;

}
    return 0;
}


#include<cstdio>
using namespace std;

const int maxn=100+7;
int a[maxn];

int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
		int cnt=0;
		for(int i=0;i<n;i++){
			if(a[i]==0){
				a[i]+=1;
				cnt++;
			}
		}
		int sum=0;
		for(int i=0;i<n;i++)
		sum+=a[i];
		if(sum==0)printf("%d\n",cnt+1);
		else printf("%d\n",cnt) ;
	}

	return 0;
}


#include<stdio.h>
int main()
{
	int t;
	int n;
	int i;
	int a[105];
	scanf("%d",&t);
	while(t--)
	{
		int zero=0;
		int plus=0;
		int mins=0;
		int sum=0;
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
			if(a[i]==0)
			zero++;
			else if (a[i]<0)
			mins+=a[i];
			else
			plus+=a[i];
		}
		if(mins+plus+zero==0)
		sum+=1;
		sum+=zero;
		printf("%d\n",sum);
	}
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=101;
int a[N];

int main(){
	int sum,n,i,t,ans;
	cin>>t;
	while(t--)
	{
		sum=0;
		ans=0;
		scanf("%d",&n);
		for(i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			if(a[i]==0) {a[i]=1; sum++;}
		}
		for(i=1;i<=n;i++)
			ans+=a[i];
		if(ans==0) sum++;
		cout<<sum<<endl;
	}return 0;
}


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

int main(){

	int t , n , mat[100],count,sum;
	bool flag;

	cin>>t;

	while(t){

		cin>>n;
		count = 0;
		sum = 0;
		flag = false;

		for(int i = 0 ; i < n ; i++)
			cin>>mat[i];

		for(int i = 0 ; i < n ; i++){
			if(mat[i] == 0){
				count++;
				mat[i] = 1;
			}

			sum += mat[i];
		}

		if(sum == 0)
			flag = true;

		if(flag)
			cout<<count+1<<endl;
		else
			cout<<count<<endl;

		t--;

	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{int t;
cin>>t;
while(t--)
{
    int n;int count=0;int ans=0;
    int sum=0;
    cin>>n;
    int arr[100];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
        if(arr[i]==0)
        count++;
    }
    ans=count;
    if((sum+count)==0)
    ans+=1;
    else if(sum=0)
    ans+=1;
    cout<<ans<<"\n";

}
}