#include <bits/stdc++.h>
using namespace std;
int main() {
  map<pair<long long, long long>, long long> m;
  vector<long long> p1, p2;
  long long n, s, i, j, k, a, u, v, w, l, k1, k2;
  cin >> n;
  while (n--) {
    cin >> a;
    if (a == 1) {
      cin >> u >> v >> w;
      j = u;
      k1 = 0, k2 = 0;
      p1.push_back(j);
      while (j != 1) {
        j = j / 2;
        p1.push_back(j);
      }
      j = v;
      p2.push_back(j);
      while (j != 1) {
        j = j / 2;
        p2.push_back(j);
      }
      for (i = 0; i < p1.size(); i++) {
        int t = 1;
        for (j = 0; j < p2.size(); j++) {
          if (p1[i] == p2[j]) {
            k1 = i;
            k2 = j;
            t = 0;
            break;
          }
        }
        if (t == 0) break;
      }
      for (i = 0; i < k1; i++) {
        m[make_pair(p1[i], p1[i + 1])] += w;
      }
      for (i = 0; i < k2; i++) {
        m[make_pair(p2[i], p2[i + 1])] += w;
      }
      p1.clear();
      p2.clear();
    } else {
      s = 0;
      cin >> u >> v;
      j = u;
      k1 = k2 = 0;
      p1.push_back(j);
      while (j != 1) {
        j = j / 2;
        p1.push_back(j);
      }
      j = v;
      p2.push_back(j);
      while (j != 1) {
        j = j / 2;
        p2.push_back(j);
      }
      for (i = 0; i < p1.size(); i++) {
        int t = 1;
        for (j = 0; j < p2.size(); j++) {
          if (p1[i] == p2[j]) {
            k1 = i;
            k2 = j;
            t = 0;
            break;
          }
        }
        if (t == 0) break;
      }
      for (i = 0; i < k1; i++) {
        s += m[make_pair(p1[i], p1[i + 1])];
      }
      for (i = 0; i < k2; i++) {
        s += m[make_pair(p2[i], p2[i + 1])];
      }
      p1.clear();
      p2.clear();
      cout << s << endl;
    }
  }
}
