#include <bits/stdc++.h>
using namespace std;
template <class T, class C>
void print(C name, T a) {
  cout << name << ": " << a << endl;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
long long pow(long long a, long long b, long long p) {
  long long ans = 1;
  a %= p;
  while (b) {
    if (b & 1) ans = ans * a % p;
    a = a * a % p;
    b >>= 1;
  }
  return ans;
}
const int maxn = 1000000 + 20, N = 5000 + 10, M = 200000 + 10;
const long long mod = 998244353;
const long long inf = 1e18;
struct node {
  int v;
  long long val;
  bool operator<(const node& A) const { return val > A.val; }
};
vector<node> a[maxn];
int id[2][maxn << 2];
int cnt = 100000 + 20;
struct pos {
  int x;
  int y;
};
pos ha[maxn];
void build(int x, int l, int r, int i) {
  id[x][i] = ++cnt;
  ha[cnt] = {l, r};
  if (l == r) {
    if (!x)
      a[id[x][i]].push_back({l, 0});
    else
      a[l].push_back({id[x][i], 0});
    return;
  }
  int mid = (l + r) >> 1;
  build(x, l, mid, i << 1);
  build(x, mid + 1, r, i << 1 | 1);
  if (!x) {
    a[id[x][i]].push_back({id[x][i << 1], 0});
    a[id[x][i]].push_back({id[x][i << 1 | 1], 0});
  } else {
    a[id[x][i << 1]].push_back({id[x][i], 0});
    a[id[x][i << 1 | 1]].push_back({id[x][i], 0});
  }
}
void query(int x, int u, int l, int r, int L, int R, int i, long long w) {
  if (L <= l && r <= R) {
    if (!x)
      a[u].push_back({id[x][i], w});
    else
      a[id[x][i]].push_back({u, w});
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) query(x, u, l, mid, L, R, i << 1, w);
  if (R > mid) query(x, u, mid + 1, r, L, R, i << 1 | 1, w);
}
long long dis[maxn];
long long flag[maxn];
void dji(int s) {
  priority_queue<node> p;
  p.push({s, 0});
  for (int i = 1; i <= maxn - 1; i++) dis[i] = inf;
  memset(flag, true, sizeof(flag));
  dis[s] = 0;
  while (!p.empty()) {
    node t = p.top();
    p.pop();
    int u = t.v;
    if (!flag[u]) continue;
    flag[u] = false;
    for (int i = 0; i < a[u].size(); i++) {
      int v = a[u][i].v;
      if (v == 4)
        ;
      int c = 1;
      long long val = a[u][i].val;
      if (dis[v] > dis[u] + val) {
        dis[v] = dis[u] + val;
        p.push({v, dis[v]});
      }
    }
  }
}
int main() {
  int n, q, s;
  scanf("%d%d%d", &n, &q, &s);
  build(0, 1, n, 1);
  build(1, 1, n, 1);
  while (q--) {
    int x, u;
    scanf("%d%d", &x, &u);
    if (x == 1) {
      int v;
      long long w;
      scanf("%d%lld", &v, &w);
      a[u].push_back({v, w});
    } else {
      int l, r;
      long long w;
      scanf("%d%d%lld", &l, &r, &w);
      query(x - 2, u, 1, n, l, r, 1, w);
    }
  }
  dji(s);
  for (int i = 1; i <= n - 1; i++) printf("%lld ", dis[i] == inf ? -1 : dis[i]);
  printf("%lld\n", dis[n] == inf ? -1 : dis[n]);
}
