#include <bits/stdc++.h>
using namespace std;
long long powm(int a, int b) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y);
      if (x > 1000000007) x %= 1000000007;
    }
    y = (y * y);
    if (y > 1000000007) y %= 1000000007;
    b /= 2;
  }
  return x;
}
int main() {
  int q;
  cin >> q;
  map<pair<long long, long long>, long long> mp;
  while (q--) {
    int num;
    cin >> num;
    if (num == 1) {
      long long u, v, w;
      cin >> u >> v >> w;
      long long tmp = u;
      set<long long> a1, a2;
      while (tmp != 0) {
        a1.insert(tmp);
        tmp /= 2;
      }
      tmp = v;
      while (tmp != 0) {
        a2.insert(tmp);
        tmp /= 2;
      }
      set<long long>::iterator it;
      long long lca = 1;
      for (it = a1.begin(); it != a1.end(); it++)
        if (a2.find(*it) != a2.end()) lca = *it;
      long long ans = 0;
      while (u > lca) {
        if (mp.find(make_pair(u / 2, u)) == mp.end())
          mp[make_pair(u / 2, u)] = w;
        else
          mp[make_pair(u / 2, u)] += w;
        u /= 2;
      }
      while (v > lca) {
        if (mp.find(make_pair(v / 2, v)) == mp.end())
          mp[make_pair(v / 2, v)] = w;
        else
          mp[make_pair(v / 2, v)] += w;
        v /= 2;
      }
    } else {
      long long v, u;
      cin >> u >> v;
      long long tmp = u;
      set<long long> a1, a2;
      while (tmp != 0) {
        a1.insert(tmp);
        tmp /= 2;
      }
      tmp = v;
      while (tmp != 0) {
        a2.insert(tmp);
        tmp /= 2;
      }
      set<long long>::iterator it;
      long long lca = 1;
      for (it = a1.begin(); it != a1.end(); it++)
        if (a2.find(*it) != a2.end()) lca = *it;
      long long ans = 0;
      while (u > lca) {
        if (mp.find(make_pair(u / 2, u)) == mp.end())
          ;
        else
          ans += mp[make_pair(u / 2, u)];
        u /= 2;
      }
      while (v > lca) {
        if (mp.find(make_pair(v / 2, v)) == mp.end())
          ;
        else
          ans += mp[make_pair(v / 2, v)];
        v /= 2;
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
