#include <bits/stdc++.h>
using namespace std;
int q;
map<long long, long long> cost;
int main() {
  scanf("%d", &q);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      long long v, u;
      int w;
      scanf("%lld%lld%d", &v, &u, &w);
      if (u > v) swap(u, v);
      set<long long> s;
      while (u != v) {
        s.insert(u);
        s.insert(v);
        if (u > v)
          u /= 2;
        else
          v /= 2;
      }
      bool f = true;
      for (auto x : s) {
        if (!f) cost[x] += w;
        f = false;
      }
    } else {
      long long v, u;
      scanf("%lld%lld", &v, &u);
      if (u > v) swap(u, v);
      set<long long> s;
      while (u != v) {
        s.insert(u);
        s.insert(v);
        if (u > v)
          u /= 2;
        else
          v /= 2;
      }
      bool f = true;
      long long sum = 0;
      for (auto x : s) {
        if (!f) sum += cost[x];
        f = false;
      }
      printf("%lld\n", sum);
    }
  }
  return 0;
}
