#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int n, m, s;
const long long max_num = 0x3f3f3f3f3f3f3f3fLL;
vector<int> to[800010];
vector<long long> len[800010];
struct tree1 {
  void down(int i, int l, int r) {
    if (l == r) return;
    to[i].push_back(i * 2);
    to[i].push_back(i * 2 + 1);
    len[i].push_back(0);
    len[i].push_back(0);
    int mid = (l + r) / 2;
    down(i * 2, l, mid);
    down(i * 2 + 1, mid + 1, r);
  }
  void Find_interval(int i, int l, int r, int L, int R, int xb, int w) {
    if (L <= l && r <= R) {
      to[xb + 4 * n].push_back(i);
      len[xb + 4 * n].push_back(w);
      to[xb + 4 * n].push_back(i + 4 * n);
      len[xb + 4 * n].push_back(w);
      return;
    }
    int mid = (l + r) / 2;
    if (L <= mid) Find_interval(i * 2, l, mid, L, R, xb, w);
    if (R > mid) Find_interval(i * 2 + 1, mid + 1, r, L, R, xb, w);
  }
  void Find_num(int i, int l, int r, int L, int R, int xb, int w) {
    if (L <= l && r <= R) {
      to[i].push_back(xb + 4 * n);
      len[i].push_back(w);
      to[i].push_back(xb);
      len[i].push_back(w);
      return;
    }
    int mid = (l + r) / 2;
    if (L <= mid) Find_num(i * 2, l, mid, L, R, xb, w);
    if (R > mid) Find_num(i * 2 + 1, mid + 1, r, L, R, xb, w);
  }
} a;
struct tree2 {
  void up(int i, int l, int r) {
    if (l == r) return;
    to[4 * n + i * 2].push_back(4 * n + i);
    to[4 * n + i * 2 + 1].push_back(4 * n + i);
    len[4 * n + i * 2].push_back(0);
    len[4 * n + i * 2 + 1].push_back(0);
    int mid = (l + r) / 2;
    up(i * 2, l, mid);
    up(i * 2 + 1, mid + 1, r);
  }
  void Find_interval(int i, int l, int r, int L, int R, int xb, int w) {
    if (L <= l && r <= R) {
      to[xb].push_back(i + 4 * n);
      len[xb].push_back(w);
      to[xb].push_back(i);
      len[xb].push_back(w);
      return;
    }
    int mid = (l + r) / 2;
    if (L <= mid) Find_interval(i * 2, l, mid, L, R, xb, w);
    if (R > mid) Find_interval(i * 2 + 1, mid + 1, r, L, R, xb, w);
  }
  void Find_num(int i, int l, int r, int L, int R, int xb, int w) {
    if (L <= l && r <= R) {
      to[i + 4 * n].push_back(xb);
      len[i + 4 * n].push_back(w);
      to[i + 4 * n].push_back(xb + 4 * n);
      len[i + 4 * n].push_back(w);
      return;
    }
    int mid = (l + r) / 2;
    if (L <= mid) Find_num(i * 2, l, mid, L, R, xb, w);
    if (R > mid) Find_num(i * 2 + 1, mid + 1, r, L, R, xb, w);
  }
} b;
int Find(int i, int x, int l, int r) {
  if (l == x && x == r) return i;
  int mid = (l + r) / 2;
  if (x <= mid)
    return Find(i * 2, x, l, mid);
  else
    return Find(i * 2 + 1, x, mid + 1, r);
}
void Read(int &x) {
  x = 0;
  int f = 1;
  char s = getchar();
  while (!isdigit(s)) {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (isdigit(s)) {
    x = x * 10 + s - '0';
    s = getchar();
  }
  x *= f;
}
long long dis[800010];
bool used[800010];
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    q;
void DJ(int u) {
  memset(used, false, sizeof(used));
  dis[u] = 0;
  q.push(make_pair(0, u));
  while (!q.empty()) {
    pair<long long, int> x = q.top();
    q.pop();
    int p = x.second;
    if (!used[p]) {
      for (size_t i = 0; i < to[p].size(); i++) {
        int v = to[p][i];
        if (dis[v] > dis[p] + len[p][i]) {
          dis[v] = dis[p] + len[p][i];
          q.push(make_pair(dis[v], v));
        }
      }
    }
    used[p] = true;
  }
}
int main() {
  Read(n);
  Read(m);
  Read(s);
  a.down(1, 1, n);
  b.up(1, 1, n);
  register int i;
  for (i = 1; i <= m; i++) {
    int t;
    Read(t);
    if (t == 1) {
      int u, v, w;
      Read(u);
      Read(v);
      Read(w);
      int xb = Find(1, u, 1, n), xx = Find(1, v, 1, n);
      to[xb].push_back(xx + 4 * n);
      len[xb].push_back(w);
      to[xb + 4 * n].push_back(xx);
      len[xb + 4 * n].push_back(w);
    } else {
      if (t == 2) {
        int u, l, r, w;
        Read(u);
        Read(l);
        Read(r);
        Read(w);
        int xb = Find(1, u, 1, n);
        b.Find_interval(1, 1, n, l, r, xb, w);
        a.Find_interval(1, 1, n, l, r, xb, w);
      } else {
        int u, l, r, w;
        Read(u);
        Read(l);
        Read(r);
        Read(w);
        int xb = Find(1, u, 1, n);
        b.Find_num(1, 1, n, l, r, xb, w);
        a.Find_num(1, 1, n, l, r, xb, w);
      }
    }
  }
  int xb = Find(1, s, 1, n);
  memset(dis, 0x3f, sizeof(dis));
  DJ(xb);
  DJ(xb + 4 * n);
  for (i = 1; i <= n; i++) {
    int fir = Find(1, i, 1, n);
    long long ans = min(dis[fir], dis[fir + 4 * n]);
    if (ans == max_num)
      cout << -1 << " ";
    else
      cout << ans << " ";
  }
  cout << endl;
  return 0;
}
