#include <bits/stdc++.h>
using namespace std;
int q, c, i1, i2;
long long v, u, w;
bool flag;
map<long long, long long> cost;
vector<long long> a, b;
void Rule() {
  for (int i = i1 - 1; i >= 0; --i) {
    cost[a[i]] += w;
  }
  for (int i = i2 - 1; i >= 0; --i) {
    cost[b[i]] += w;
  }
}
long long Cuddle() {
  long long ret = 0;
  for (int i = i1 - 1; i >= 0; --i) {
    ret += cost[a[i]];
  }
  for (int i = i2 - 1; i >= 0; --i) {
    ret += cost[b[i]];
  }
  return ret;
}
int main() {
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &c);
    a.clear(), b.clear();
    cin >> v >> u;
    while (v) {
      a.push_back(v);
      if (v % 2)
        v = (v - 1) / 2;
      else
        v /= 2;
    }
    while (u) {
      b.push_back(u);
      if (u % 2)
        u = (u - 1) / 2;
      else
        u /= 2;
    }
    flag = 0;
    for (int i = 0; i < ((int)(a).size()); ++i) {
      for (int j = 0; j < ((int)(b).size()); ++j) {
        if (a[i] == b[j]) {
          i1 = i, i2 = j, flag = 1;
          break;
        }
      }
      if (flag) break;
    }
    if (c == 1)
      cin >> w, Rule();
    else
      printf("%I64d\n", Cuddle());
  }
}
