#include <bits/stdc++.h>
using namespace std;
int n, qu, st, treenode, lech[900004], rich[900004];
vector<pair<int, int> > v[900005];
struct info {
  int pos;
  long long w;
  info(int a, long long b) { pos = a, w = b; }
  bool operator<(const info &i) const {
    if (w != i.w) return w > i.w;
    return pos > i.pos;
  }
};
void build(int num, int L, int R) {
  if (L == R) {
    v[num].push_back(make_pair(L, 0));
    return;
  }
  int mid = (L + R) >> 1;
  lech[num] = ++treenode;
  v[num].push_back(make_pair(treenode, 0));
  rich[num] = ++treenode;
  v[num].push_back(make_pair(treenode, 0));
  build(lech[num], L, mid);
  build(rich[num], mid + 1, R);
}
void build2(int num, int L, int R) {
  if (L == R) {
    v[L].push_back(make_pair(num, 0));
    return;
  }
  int mid = (L + R) >> 1;
  lech[num] = ++treenode;
  v[lech[num]].push_back(make_pair(num, 0));
  rich[num] = ++treenode;
  v[rich[num]].push_back(make_pair(num, 0));
  build2(lech[num], L, mid);
  build2(rich[num], mid + 1, R);
}
void linking(int me, int num, int L, int R, int le, int ri, int w) {
  if (ri < L || R < le) return;
  if (le <= L && R <= ri) {
    v[me].push_back(make_pair(num, w));
    return;
    return;
  }
  int mid = (L + R) >> 1;
  linking(me, lech[num], L, mid, le, ri, w);
  linking(me, rich[num], mid + 1, R, le, ri, w);
}
void link2(int num, int L, int R, int le, int ri, int target, int w) {
  if (ri < L || R < le) return;
  if (le <= L && R <= ri) {
    v[num].push_back(make_pair(target, w));
    return;
    return;
  }
  int mid = (L + R) >> 1;
  link2(lech[num], L, mid, le, ri, target, w);
  link2(rich[num], mid + 1, R, le, ri, target, w);
}
priority_queue<info> pq;
vector<long long> dist;
int main() {
  scanf("%d %d %d", &n, &qu, &st);
  treenode = n + 1;
  int R1 = treenode;
  build(n + 1, 1, n);
  int R2 = ++treenode;
  build2(R2, 1, n);
  for (int ty, a, b, c, d, ite = 1; ite <= qu; ite++) {
    scanf("%d", &ty);
    if (ty == 1) {
      scanf("%d %d %d", &a, &b, &c);
      v[a].push_back(make_pair(b, c));
    } else if (ty == 2) {
      scanf("%d %d %d %d", &a, &b, &c, &d);
      linking(a, R1, 1, n, b, c, d);
    } else {
      scanf("%d %d %d %d", &a, &b, &c, &d);
      link2(R2, 1, n, b, c, a, d);
    }
  }
  dist = vector<long long>(n * 8 + n + 5, 0xfffffffffffff);
  pq.push(info(st, 0));
  dist[st] = 0;
  while (!pq.empty()) {
    info now = pq.top();
    pq.pop();
    for (int i = 0; i < v[now.pos].size(); i++) {
      int next = v[now.pos][i].first;
      if (dist[next] > now.w + v[now.pos][i].second) {
        dist[next] = now.w + v[now.pos][i].second;
        pq.push(info(next, dist[next]));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dist[i] != 0xfffffffffffff) {
      printf("%I64d ", dist[i]);
    } else {
      printf("-1 ");
    }
  }
}
