#include <bits/stdc++.h>
using namespace std;
map<long long, map<long long, long long> > mm;
map<long long, long long> m;
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    long long x, u, v, w;
    scanf("%I64d %I64d %I64d", &x, &u, &v);
    if (x == 1) {
      long long d;
      scanf("%I64d", &w);
      long long a = u, b = v;
      while (a) {
        m[a] = 1;
        a /= 2;
      }
      while (b) {
        if (m[b]) {
          d = b;
          break;
        }
        m[b] = 1;
        b /= 2;
      }
      while (1) {
        if (u == d) break;
        long long abc = u;
        u /= 2;
        mm[u][abc] += w;
        mm[abc][u] += w;
        if (u == d) break;
      }
      while (1) {
        if (v == d) break;
        long long abc = v;
        v /= 2;
        mm[abc][v] += w;
        mm[v][abc] += w;
        if (v == d) break;
      }
      m.clear();
    } else {
      long long ans = 0;
      long long a = u, b = v;
      while (a) {
        m[a] = 1;
        a /= 2;
      }
      long long d;
      while (b) {
        if (m[b]) {
          d = b;
          break;
        }
        m[b] = 1;
        b /= 2;
      }
      while (u) {
        if (u == d) break;
        long long abc = u;
        u /= 2;
        ans += mm[abc][u];
        if (u == d) break;
      }
      while (v) {
        if (v == d) break;
        long long abc = v;
        v /= 2;
        ans += mm[abc][v];
      }
      m.clear();
      printf("%I64d\n", ans);
    }
  }
}
