#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n-1;i++){
		int u,v;
		cin>>u>>v;
		int q;
		cin>>q;
		while(q--){
			int l,r,k;
			cin>>l>>r>>k;
			cout<<(l+r+k)/3<<endl;
		}
	}
	return 0;
}

