#include <bits/stdc++.h>
using namespace std;
int dirK[8][2] = {{-2, 1}, {-1, 2},  {1, 2},  {2, 1},
                  {2, -1}, {-1, -2}, {1, -2}, {-2, -1}};
int dir8[8][2] = {{-1, 0},  {0, 1}, {1, 0},  {0, -1},
                  {-1, -1}, {1, 1}, {1, -1}, {-1, 1}};
int dir4[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
map<pair<long long, long long>, long long> mll;
void update(long long u, long long v, int w) {
  if (u == v) {
    return;
  }
  mll[make_pair(v, v / 2)] += w;
  update(min(u, v / 2), max(u, v / 2), w);
}
long long query(long long u, long long v) {
  if (u == v) {
    return 0;
  }
  return mll[make_pair(v, v / 2)] + query(min(u, v / 2), max(u, v / 2));
}
int main() {
  int q, n, w, i;
  long long u, v, sum, start, j;
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &n, &u, &v);
    cin >> u >> v;
    if (u > v) {
      swap(u, v);
    }
    if (n == 1) {
      scanf("%d", &w);
      update(u, v, w);
    } else {
      cout << query(u, v) << endl;
    }
  }
}
