#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;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpzdHJ1Y3QgQ29tcGFyZXIgewogICAgYm9vbCBvcGVyYXRvcigpIChjb25zdCBwYWlyPGJpdHNldDw2ND4sYml0c2V0PDY0Pj4gJmIxLCBjb25zdCBwYWlyPGJpdHNldDw2ND4sYml0c2V0PDY0Pj4gJmIyKSBjb25zdCB7CiAgICAgICAgaWYoYjEuZmlyc3QudG9fdWxsb25nKCk9PWIyLmZpcnN0LnRvX3VsbG9uZygpKXJldHVybiBiMS5zZWNvbmQudG9fdWxsb25nKCkgPCBiMi5zZWNvbmQudG9fdWxsb25nKCk7CiAgICAgICAgcmV0dXJuIGIxLmZpcnN0LnRvX3VsbG9uZygpPGIyLmZ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