#include <bits/stdc++.h>

using namespace std;
struct Comparer {
    bool operator() (const pair<bitset<64>,bitset<64>> &b1, const pair<bitset<64>,bitset<64>> &b2) const {
        if(b1.first.to_ullong()==b2.first.to_ullong())return b1.second.to_ullong() < b2.second.to_ullong();
        return b1.first.to_ullong()<b2.first.to_ullong();
    }
};
int main()
{
	ios_base::sync_with_stdio(0);

	int q;
	cin >> q;
	map<pair<bitset<64>,bitset<64>>, long long,Comparer > cost;
	for (int i=0; i<q; i++)
	{
		int a;
		cin >> a;
		if (a==1)
		{
			long long v, u ,w;
			cin >> v >> u >> w;
			bitset<64> x(u);
			bitset<64> y(v);
			int dist;
			for (int i=0; i<64; i++)
			{
				if (x[i] != y[i])
				{
					dist=i;
					break;
				}
			}
			for (int i=0; i<dist; i++)
			{
				cost[{x,x>>1}]+=w;
				x>>=1;
				cost[{y>>1,y}]+=w;
				y>>=1;
			}
		}
		if (a==2)
		{
			long long v, u;
			cin >> v >> u;
			bitset<64> x(v);
			bitset<64> y(u);
			long long price=0;
			int dist;
			for (int i=0; i<64; i++)
			{
				if (x[i] != y[i])
				{
					dist=i;
					break;
				}
			}
			for (int i=0; i<dist; i++)
			{
				price+=cost[{x,x>>1}];
				x>>=1;
				price+=cost[{y>>1, y}];
				y>>=1;
			}
			cout << price <<endl;
		}
	}

	return 0;
}
