#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  scanf("%d", &q);
  map<long long, long long> road;
  for (int i = 0; i < q; i++) {
    int s;
    scanf("%d", &s);
    if (s == 1) {
      long long u, v, w;
      scanf("%I64d %I64d %I64d", &u, &v, &w);
      while (u != v) {
        if (u > v) {
          road[u] += w;
          u /= 2;
        } else {
          road[v] += w;
          v /= 2;
        }
      }
    } else if (s == 2) {
      long long u, v;
      scanf("%I64d %I64d", &u, &v);
      long long result = 0;
      while (u != v) {
        if (u > v) {
          result += road[u];
          u /= 2;
        } else {
          result += road[v];
          v /= 2;
        }
      }
      printf("%I64d\n", result);
    }
  }
  return 0;
}
