stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <math.h>

#include <vector>

#include <string>

using namespace std;

int main() {

	int N = 0;

	scanf("%d", &N);

	vector<long>v (N+1,0);



	/*

	for (int x = 1; x <= 100; x++) {

		for (int y = 1; y <= 100; y++) {

			for (int z = 1; z <= 100; z++) {

				if ((x * x + y * y + z * z + x * y + x * z + z * y) != 0 && ((x * x + y * y + z * z + x * y + x * z + z * y) < v.size())) {

					v[(x * x + y * y + z * z + x * y + x * z + z * y) - 1]++;

				}

				

			}

			

		}

		

	}*/



	for (int i = 1; i <= 100; i++) {

		for (int w = 1; w <= 100; w++) {

			for (int y = 1; y <= 100; y++) {

				if (((i * i) + (w * w) + (y * y) + (i * w) + (i * y) + (y * w)) <= v.size()) {

					v[((i * i) + (w * w) + (y * y) + (i * w) + (i * y) + (y * w))]++;



				}



			}



		}

	}

	

	for (int i = 1; i <= N; i++) {

		string str = to_string(v[i]);

		const char* l = str.c_str();

		printf(l);

		printf("\n");

	}

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.838037847933115x):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {

    ll equa;

    int n;

    cin>>n;

    int arr[n+1];

    for(int i=1;i<=n;i++){

        arr[i]=0;

    }

    for(int i=1;i*i<=n;i++){

        for(int j=1;j*j<=n;j++){

            for(int z=1;z*z<=n;z++){

              equa = i*i + j*j + z*z + i*j + i*z + j*z;

              if(equa>0 && equa<=n){

                  arr[equa]++;

              }

              else if(equa>n){

                  break;

              }   

            }

        }

    }

    for(int i=1;i<=n;i++){

        cout<<arr[i]<<endl;

    }

    return 0;



}
// Slower C++ solution:
/*

*         ****FOX****

*/

#include <iostream>

#include <string>

#include <algorithm>

#include <stack>

#include <queue>

#include <vector>

#include <map>

#include <set>

#include <sstream>

#include <iomanip>

#include <cmath>

#include <limits>

//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

#include <utility>

#include <list>

#include <cstdio>

#include<forward_list>

#include<algorithm>

#include<string>

#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pi 3.1415926536

#define ll long long

#define ull unsigned long long

#define lli long long int

using namespace std;

int main()

{

    Omar_Hafez

   int n; cin >> n;

    vector<int> v(n,0); 

    for (int i = 1; i < 400; i++)

    {

        for (int j = 1; j < 400; j++)

        {

            for (int z = 1; z < 400; z++)

            {

                int res = (i * i) + (j * j) + (z * z) + (i * j) + (j * z) + (i * z);  

                if (res <= n)  v[--res]++;

                else break;

            }

        }

    }

    for (int i = 0; i< v.size(); i++) cout << v[i] << "\n";

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.5035385311914071x):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {

    ll equa;

    int n;

    cin>>n;

    int arr[n+1];

    for(int i=1;i<=n;i++){

        arr[i]=0;

    }

    for(int i=1;i*i<=n;i++){

        for(int j=1;j*j<=n;j++){

            for(int z=1;z*z<=n;z++){

              equa = i*i + j*j + z*z + i*j + i*z + j*z;

              if(equa>0 && equa<=n){

                  arr[equa]++;

              }

              else if(equa>n){

                  break;

              }   

            }

        }

    }

    for(int i=1;i<=n;i++){

        cout<<arr[i]<<endl;

    }

    return 0;



}
// Slower C++ solution:
#include <iostream>

#include <vector>

using namespace std;



int formula(int x,int y,int z) {

    int ans = x*x+y*y+z*z+x*y+x*z+y*z;

    return ans;

}



int main()

{

    int n;

    cin>>n;

    int x(1),y(1),z(1),formul(0),c(0);

    for (int i=1;i<=n;i++)  {

        for (int x=1;x<=99;x++) {

            for (int y=1;y<=99;y++) {

               for (int z=1;z<=99;z++) {

                    formul=formula(x,y,z);

                    if (formul==i) c++;

                    if (formul>i) break;

                }

            }

        }

        

        cout<<c<<endl;

        c=0;

    }

}

// Faster C++ solution for the same problem (measured speedup: 3.499130089250432x):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {

    ll equa;

    int n;

    cin>>n;

    int arr[n+1];

    for(int i=1;i<=n;i++){

        arr[i]=0;

    }

    for(int i=1;i*i<=n;i++){

        for(int j=1;j*j<=n;j++){

            for(int z=1;z*z<=n;z++){

              equa = i*i + j*j + z*z + i*j + i*z + j*z;

              if(equa>0 && equa<=n){

                  arr[equa]++;

              }

              else if(equa>n){

                  break;

              }   

            }

        }

    }

    for(int i=1;i<=n;i++){

        cout<<arr[i]<<endl;

    }

    return 0;



}
// Slower C++ solution:
#include <iostream>

#include <math.h>

#include <vector>

#include <string>

using namespace std;

int main() {

	int N = 0;

	scanf("%d", &N);

	vector<long>v (N+1,0);



	/*

	for (int x = 1; x <= 100; x++) {

		for (int y = 1; y <= 100; y++) {

			for (int z = 1; z <= 100; z++) {

				if ((x * x + y * y + z * z + x * y + x * z + z * y) != 0 && ((x * x + y * y + z * z + x * y + x * z + z * y) < v.size())) {

					v[(x * x + y * y + z * z + x * y + x * z + z * y) - 1]++;

				}

				

			}

			

		}

		

	}*/



	for (int i = 1; i <= 100; i++) {

		for (int w = 1; w <= 100; w++) {

			for (int y = 1; y <= 100; y++) {

				if (((i * i) + (w * w) + (y * y) + (i * w) + (i * y) + (y * w)) <= v.size()) {

					v[((i * i) + (w * w) + (y * y) + (i * w) + (i * y) + (y * w))]++;



				}



			}



		}

	}

	

	for (int i = 1; i <= N; i++) {

		string str = to_string(v[i]);

		const char* l = str.c_str();

		printf(l);

		printf("\n");

	}

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2407197182898984x):
#include <bits/stdc++.h>



using namespace std;



int main()

{



    int n, v;

    cin >> n;



    int a[10050] = {0};



    for (size_t i = 1; i <= 104; i++)

    {

        for (size_t j = 1; j <= 104; j++)

        {

            for (size_t k = 1; k <= 104; k++)

            {

                v = i*i + j*j + k*k + i*j + j*k + i*k;

                if(v < 10050)

                    a[v]++;

            }

        }

    }



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

    {

        cout << a[i + 1] << "\n";

    }

    

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <math.h>

#include <vector>

#include <string>

using namespace std;

int main() {

	int N = 0;

	scanf("%d", &N);

	vector<long>v (N+1,0);



	/*

	for (int x = 1; x <= 100; x++) {

		for (int y = 1; y <= 100; y++) {

			for (int z = 1; z <= 100; z++) {

				if ((x * x + y * y + z * z + x * y + x * z + z * y) != 0 && ((x * x + y * y + z * z + x * y + x * z + z * y) < v.size())) {

					v[(x * x + y * y + z * z + x * y + x * z + z * y) - 1]++;

				}

				

			}

			

		}

		

	}*/



	for (int i = 1; i <= 100; i++) {

		for (int w = 1; w <= 100; w++) {

			for (int y = 1; y <= 100; y++) {

				if (((i * i) + (w * w) + (y * y) + (i * w) + (i * y) + (y * w)) <= v.size()) {

					v[((i * i) + (w * w) + (y * y) + (i * w) + (i * y) + (y * w))]++;



				}



			}



		}

	}

	

	for (int i = 1; i <= N; i++) {

		string str = to_string(v[i]);

		const char* l = str.c_str();

		printf(l);

		printf("\n");

	}

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4932978584471646x):
#include <bits/stdc++.h>

#define int long long

using namespace std;



signed main() 

{

	int t;

	cin >> t;

	for(int i = 1; i <= t; i++){

		int cnt = 0;

		for(int x = 1; x * x <= i; x++){

			for(int y = 1; y <= x; y++){

				for(int z = 1; z <= y; z++){

					if(x*x+y*y+z*z+x*z+x*y+y*z == i){

						if(x!=y && y!=z && x!=z){

							cnt += 6;

						}

						if(x!=y && y!=z && x==z){

							cnt += 3;

						}

						if(x==y && y!=z && x!=z){

							cnt += 3;

						}

						if(x!=y && y==z && x!=z){

							cnt += 3;

						}

						if(x==y && y==z && x==z){

							cnt += 1;

						}

					}

				}

			}	

		}

		cout << cnt << '\n';

	}

}
// Slower C++ solution:
/*

*         ****FOX****

*/

#include <iostream>

#include <string>

#include <algorithm>

#include <stack>

#include <queue>

#include <vector>

#include <map>

#include <set>

#include <sstream>

#include <iomanip>

#include <cmath>

#include <limits>

//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

#include <utility>

#include <list>

#include <cstdio>

#include<forward_list>

#include<algorithm>

#include<string>

#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pi 3.1415926536

#define ll long long

#define ull unsigned long long

#define lli long long int

using namespace std;

int main()

{

    Omar_Hafez

   int n; cin >> n;

    vector<int> v(n,0); 

    for (int i = 1; i < 400; i++)

    {

        for (int j = 1; j < 400; j++)

        {

            for (int z = 1; z < 400; z++)

            {

                int res = (i * i) + (j * j) + (z * z) + (i * j) + (j * z) + (i * z);  

                if (res <= n)  v[--res]++;

                else break;

            }

        }

    }

    for (int i = 0; i< v.size(); i++) cout << v[i] << "\n";

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.3684877896480998x):
#include <bits/stdc++.h>

#define int long long

using namespace std;



signed main() 

{

	int t;

	cin >> t;

	for(int i = 1; i <= t; i++){

		int cnt = 0;

		for(int x = 1; x * x <= i; x++){

			for(int y = 1; y <= x; y++){

				for(int z = 1; z <= y; z++){

					if(x*x+y*y+z*z+x*z+x*y+y*z == i){

						if(x!=y && y!=z && x!=z){

							cnt += 6;

						}

						if(x!=y && y!=z && x==z){

							cnt += 3;

						}

						if(x==y && y!=z && x!=z){

							cnt += 3;

						}

						if(x!=y && y==z && x!=z){

							cnt += 3;

						}

						if(x==y && y==z && x==z){

							cnt += 1;

						}

					}

				}

			}	

		}

		cout << cnt << '\n';

	}

}
// Slower C++ solution:
#include <iostream>

#include <vector>

using namespace std;



int formula(int x,int y,int z) {

    int ans = x*x+y*y+z*z+x*y+x*z+y*z;

    return ans;

}



int main()

{

    int n;

    cin>>n;

    int x(1),y(1),z(1),formul(0),c(0);

    for (int i=1;i<=n;i++)  {

        for (int x=1;x<=99;x++) {

            for (int y=1;y<=99;y++) {

               for (int z=1;z<=99;z++) {

                    formul=formula(x,y,z);

                    if (formul==i) c++;

                    if (formul>i) break;

                }

            }

        }

        

        cout<<c<<endl;

        c=0;

    }

}

// Faster C++ solution for the same problem (measured speedup: 3.4109578003619005x):
#include <bits/stdc++.h>

#define int long long

using namespace std;



signed main() 

{

	int t;

	cin >> t;

	for(int i = 1; i <= t; i++){

		int cnt = 0;

		for(int x = 1; x * x <= i; x++){

			for(int y = 1; y <= x; y++){

				for(int z = 1; z <= y; z++){

					if(x*x+y*y+z*z+x*z+x*y+y*z == i){

						if(x!=y && y!=z && x!=z){

							cnt += 6;

						}

						if(x!=y && y!=z && x==z){

							cnt += 3;

						}

						if(x==y && y!=z && x!=z){

							cnt += 3;

						}

						if(x!=y && y==z && x!=z){

							cnt += 3;

						}

						if(x==y && y==z && x==z){

							cnt += 1;

						}

					}

				}

			}	

		}

		cout << cnt << '\n';

	}

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



int main()

{



    int n, v;

    cin >> n;



    int a[10050] = {0};



    for (size_t i = 1; i <= 104; i++)

    {

        for (size_t j = 1; j <= 104; j++)

        {

            for (size_t k = 1; k <= 104; k++)

            {

                v = i*i + j*j + k*k + i*j + j*k + i*k;

                if(v < 10050)

                    a[v]++;

            }

        }

    }



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

    {

        cout << a[i + 1] << "\n";

    }

    

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.8155415013972913x):
#include <bits/stdc++.h>

#define int long long

using namespace std;



signed main() 

{

	int t;

	cin >> t;

	for(int i = 1; i <= t; i++){

		int cnt = 0;

		for(int x = 1; x * x <= i; x++){

			for(int y = 1; y <= x; y++){

				for(int z = 1; z <= y; z++){

					if(x*x+y*y+z*z+x*z+x*y+y*z == i){

						if(x!=y && y!=z && x!=z){

							cnt += 6;

						}

						if(x!=y && y!=z && x==z){

							cnt += 3;

						}

						if(x==y && y!=z && x!=z){

							cnt += 3;

						}

						if(x!=y && y==z && x!=z){

							cnt += 3;

						}

						if(x==y && y==z && x==z){

							cnt += 1;

						}

					}

				}

			}	

		}

		cout << cnt << '\n';

	}

}
// Slower C++ solution:
#include <iostream>

#include <math.h>

#include <vector>

#include <string>

using namespace std;

int main() {

	int N = 0;

	scanf("%d", &N);

	vector<long>v (N+1,0);



	/*

	for (int x = 1; x <= 100; x++) {

		for (int y = 1; y <= 100; y++) {

			for (int z = 1; z <= 100; z++) {

				if ((x * x + y * y + z * z + x * y + x * z + z * y) != 0 && ((x * x + y * y + z * z + x * y + x * z + z * y) < v.size())) {

					v[(x * x + y * y + z * z + x * y + x * z + z * y) - 1]++;

				}

				

			}

			

		}

		

	}*/



	for (int i = 1; i <= 100; i++) {

		for (int w = 1; w <= 100; w++) {

			for (int y = 1; y <= 100; y++) {

				if (((i * i) + (w * w) + (y * y) + (i * w) + (i * y) + (y * w)) <= v.size()) {

					v[((i * i) + (w * w) + (y * y) + (i * w) + (i * y) + (y * w))]++;



				}



			}



		}

	}

	

	for (int i = 1; i <= N; i++) {

		string str = to_string(v[i]);

		const char* l = str.c_str();

		printf(l);

		printf("\n");

	}

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.150719749540893x):
#include<bits/stdc++.h>

#define ll long long

using namespace std;





int main (){

	ll n;

	cin >> n;

	for(int i=1; i<=n; i++){

		ll z=2*i,jwb=0;

		for(int j=2; j<=sqrt(z); j++){

			for(int k=2; k*k+j*j<=z; k++){

				ll l=z-j*j-k*k;

				if(l>=4 && trunc(sqrt(l))==sqrt(l)){

					ll x=(j+k+sqrt(l))/2-sqrt(l),y=(j+k+sqrt(l))/2-k,z=(j+k+sqrt(l))/2-j;

					if(x>=1 && y>=1 && z>=1)jwb++;

				}

			}

		}

		cout << jwb << endl;

	}

	

}
// Slower C++ solution:
/*

*         ****FOX****

*/

#include <iostream>

#include <string>

#include <algorithm>

#include <stack>

#include <queue>

#include <vector>

#include <map>

#include <set>

#include <sstream>

#include <iomanip>

#include <cmath>

#include <limits>

//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

#include <utility>

#include <list>

#include <cstdio>

#include<forward_list>

#include<algorithm>

#include<string>

#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pi 3.1415926536

#define ll long long

#define ull unsigned long long

#define lli long long int

using namespace std;

int main()

{

    Omar_Hafez

   int n; cin >> n;

    vector<int> v(n,0); 

    for (int i = 1; i < 400; i++)

    {

        for (int j = 1; j < 400; j++)

        {

            for (int z = 1; z < 400; z++)

            {

                int res = (i * i) + (j * j) + (z * z) + (i * j) + (j * z) + (i * z);  

                if (res <= n)  v[--res]++;

                else break;

            }

        }

    }

    for (int i = 0; i< v.size(); i++) cout << v[i] << "\n";

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.2342839576143303x):
#include<bits/stdc++.h>

#define ll long long

using namespace std;





int main (){

	ll n;

	cin >> n;

	for(int i=1; i<=n; i++){

		ll z=2*i,jwb=0;

		for(int j=2; j<=sqrt(z); j++){

			for(int k=2; k*k+j*j<=z; k++){

				ll l=z-j*j-k*k;

				if(l>=4 && trunc(sqrt(l))==sqrt(l)){

					ll x=(j+k+sqrt(l))/2-sqrt(l),y=(j+k+sqrt(l))/2-k,z=(j+k+sqrt(l))/2-j;

					if(x>=1 && y>=1 && z>=1)jwb++;

				}

			}

		}

		cout << jwb << endl;

	}

	

}
// Slower C++ solution:
#include <iostream>

#include <vector>

using namespace std;



int formula(int x,int y,int z) {

    int ans = x*x+y*y+z*z+x*y+x*z+y*z;

    return ans;

}



int main()

{

    int n;

    cin>>n;

    int x(1),y(1),z(1),formul(0),c(0);

    for (int i=1;i<=n;i++)  {

        for (int x=1;x<=99;x++) {

            for (int y=1;y<=99;y++) {

               for (int z=1;z<=99;z++) {

                    formul=formula(x,y,z);

                    if (formul==i) c++;

                    if (formul>i) break;

                }

            }

        }

        

        cout<<c<<endl;

        c=0;

    }

}

// Faster C++ solution for the same problem (measured speedup: 3.23794758223402x):
#include<bits/stdc++.h>

#define ll long long

using namespace std;





int main (){

	ll n;

	cin >> n;

	for(int i=1; i<=n; i++){

		ll z=2*i,jwb=0;

		for(int j=2; j<=sqrt(z); j++){

			for(int k=2; k*k+j*j<=z; k++){

				ll l=z-j*j-k*k;

				if(l>=4 && trunc(sqrt(l))==sqrt(l)){

					ll x=(j+k+sqrt(l))/2-sqrt(l),y=(j+k+sqrt(l))/2-k,z=(j+k+sqrt(l))/2-j;

					if(x>=1 && y>=1 && z>=1)jwb++;

				}

			}

		}

		cout << jwb << endl;

	}

	

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



int main()

{



    int n, v;

    cin >> n;



    int a[10050] = {0};



    for (size_t i = 1; i <= 104; i++)

    {

        for (size_t j = 1; j <= 104; j++)

        {

            for (size_t k = 1; k <= 104; k++)

            {

                v = i*i + j*j + k*k + i*j + j*k + i*k;

                if(v < 10050)

                    a[v]++;

            }

        }

    }



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

    {

        cout << a[i + 1] << "\n";

    }

    

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.5394290935293387x):
#include<bits/stdc++.h>

#define ll long long

using namespace std;





int main (){

	ll n;

	cin >> n;

	for(int i=1; i<=n; i++){

		ll z=2*i,jwb=0;

		for(int j=2; j<=sqrt(z); j++){

			for(int k=2; k*k+j*j<=z; k++){

				ll l=z-j*j-k*k;

				if(l>=4 && trunc(sqrt(l))==sqrt(l)){

					ll x=(j+k+sqrt(l))/2-sqrt(l),y=(j+k+sqrt(l))/2-k,z=(j+k+sqrt(l))/2-j;

					if(x>=1 && y>=1 && z>=1)jwb++;

				}

			}

		}

		cout << jwb << endl;

	}

	

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



pair <long long, long long> dis[310][310];



vector <pair<long long, long long>> ed[310];



void solve(long long v, long long l){

	

	priority_queue <pair<pair<long long, long long>, long long>> q;

	

	q.push(make_pair(make_pair(0, l), v));

	

	dis[v][v] = make_pair(0, l);

	

	while(!q.empty()){

		

		long long t = -q.top().first.first, c = q.top().first.second, x = q.top().second;

		

		q.pop();

		

		if(dis[v][x].first == t && dis[v][x].second == c){

			

			for(long long i = 0; i < (long long)ed[x].size(); i++){

				

				long long tx = t + (ed[x][i].second > c), cx = (ed[x][i].second > c) ? (l - ed[x][i].second) : (c - ed[x][i].second), xx = ed[x][i].first;

				

				if(cx < 0) continue;

				else if((dis[v][xx].first == -1) || ((dis[v][xx].first > tx) || ((dis[v][xx].first == tx) && (dis[v][xx].second < cx)))){

					q.push(make_pair(make_pair(-tx, cx), xx));

					dis[v][xx].first = tx;

					dis[v][xx].second = cx;

				}

			}

		}

	}

}

			

		

int main(){

	

	for(long long i = 0; i < 310; i++) for(long long j = 0; j < 310; j++) dis[i][j].first = -1;

	

	long long n, m, l;

	scanf("%lld %lld %lld", &n, &m, &l);

	

	for(long long i = 0; i < m; i++){

		long long u, v, x;

		scanf(" %lld %lld %lld", &u, &v, &x);

		

		ed[u].push_back(make_pair(v, x));

		ed[v].push_back(make_pair(u, x));

	}

	

	for(long long i = 0; i < n; i++) solve(i + 1, l);

	

	long long q;

	scanf(" %lld", &q);

	

	for(long long i = 0; i < q; i++){

		long long s, t;

		scanf(" %lld %lld", &s, &t);

		

		printf("%lld\n", dis[s][t].first);

	}

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.5395948600886427x):
#include<bits/stdc++.h>

#define ll long long

using namespace std;

ll dp[1050][1000],mp[1050][1050];

void floyd(int n){	

    for(int k=1;k<=n;k++){

        for(int i=1;i<=n;i++){

          	for(int j=1;j<=n;j++){

            	if(dp[i][j]>dp[i][k]+dp[k][j]){

            		dp[i][j]=dp[i][k]+dp[k][j];

         		}

          	}

    	}

    }

}

void floyd2(int n){	

    for(int k=1;k<=n;k++){

        for(int i=1;i<=n;i++){

          	for(int j=1;j<=n;j++){

            	if(mp[i][j]>mp[i][k]+mp[k][j]){

            		mp[i][j]=mp[i][k]+mp[k][j];

         		}

          	}

    	}

    }

}

void solve(){

	int n,m,l,u,v,q,tmpu,tmpv,flu;

	ll ans=0;

	ll w;

	scanf("%d%d%d",&n,&m,&l);

	flu=l;

	for(int i=1;i<=n;i++){

		for(int j=1;j<=n;j++){

			dp[i][j]=1e18;

			if(i==j)dp[i][j]=0;

		}

	}

	for(int i=1;i<=m;i++){

		scanf("%d%d%lld",&u,&v,&w);

		if(w>l)continue;

		dp[u][v]=w;

		dp[v][u]=w;

	}

	floyd(n);

	for(int i=1;i<=n;i++){

		for(int j=1;j<=n;j++){

			if(dp[i][j]<=l)mp[i][j]=1;

			else mp[i][j]=1e18;

		}

	}

	floyd2(n);

	scanf("%d",&q);

	for(int i=1;i<=q;i++){

		scanf("%d %d",&u,&v);

		if(mp[u][v]==1e18){

			printf("-1\n");

			continue;

		}

		printf("%lld\n",mp[u][v]-1);

	}

}

signed main(){

    int t=1;

    //scanf("%d",&t);

    for(int i=1;i<=t;i++){

        solve();

    }

    return 0;

}