#include <bits/stdc++.h>
const long long MAXN = 1e5 + 5;
template <typename _T>
void read(_T &x) {
  x = 0;
  char s = getchar();
  long long f = 1;
  while (s > '9' || s < '0') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s - '0'), s = getchar();
  }
  x *= f;
}
template <typename _T>
void write(_T x) {
  if (x < 0) {
    putchar('-');
    x = (~x) + 1;
  }
  if (9 < x) {
    write(x / 10);
  }
  putchar(x % 10 + '0');
}
template <typename _T>
_T MAX(const _T a, const _T b) {
  return a > b ? a : b;
}
struct segmentTreeNode {
  long long l, r;
  long long cnt[10];
  long long lazy[10];
} segTree[MAXN << 2];
long long a[MAXN];
long long p[10];
long long N, Q;
void normalize(const long long now) {
  long long cnt1[10], cnt2[10];
  long long ns1[10], ns2[10];
  for (long long i = 0; i < 10; i++)
    ns1[i] = segTree[now << 1].lazy[i], ns2[i] = segTree[now << 1 | 1].lazy[i];
  for (long long i = 0; i < 10; i++)
    cnt1[i] = segTree[now << 1].cnt[i], cnt2[i] = segTree[now << 1 | 1].cnt[i];
  for (long long i = 0; i < 10; i++) {
    if (segTree[now].lazy[i] ^ i) {
      for (long long j = 0; j < 10; j++) {
        if (segTree[now << 1].lazy[j] == i) ns1[j] = segTree[now].lazy[i];
        if (segTree[now << 1 | 1].lazy[j] == i) ns2[j] = segTree[now].lazy[i];
      }
      cnt1[segTree[now].lazy[i]] += segTree[now << 1].cnt[i];
      cnt2[segTree[now].lazy[i]] += segTree[now << 1 | 1].cnt[i];
      cnt1[i] -= segTree[now << 1].cnt[i];
      cnt2[i] -= segTree[now << 1 | 1].cnt[i];
    }
    segTree[now].lazy[i] = i;
  }
  for (long long i = 0; i < 10; i++)
    segTree[now << 1].lazy[i] = ns1[i], segTree[now << 1 | 1].lazy[i] = ns2[i],
                   segTree[now << 1].cnt[i] = cnt1[i],
                   segTree[now << 1 | 1].cnt[i] = cnt2[i];
}
void upt(const long long now) {
  for (long long i = 0; i < 10; i++)
    segTree[now].cnt[i] =
        segTree[now << 1].cnt[i] + segTree[now << 1 | 1].cnt[i];
}
void build(const long long now, const long long left, const long long right) {
  segTree[now].l = left, segTree[now].r = right;
  for (long long i = 0; i < 10; i++) segTree[now].lazy[i] = i;
  if ((segTree[now].l == segTree[now].r)) {
    for (long long i = 0; i < 10 && p[i] <= a[left]; i++)
      segTree[now].cnt[(a[left] / p[i]) % 10] += p[i];
    return;
  }
  build(now << 1, left, (left + right) >> 1);
  build(now << 1 | 1, ((left + right) >> 1) + 1, right);
  upt(now);
}
void update(const long long now, const long long segL, const long long segR,
            const long long sta, const long long ed) {
  if (segR < segTree[now].l || segTree[now].r < segL) return;
  if (segL <= segTree[now].l && segTree[now].r <= segR) {
    if (sta == ed) return;
    segTree[now].cnt[ed] += segTree[now].cnt[sta], segTree[now].cnt[sta] = 0;
    long long tmp[10];
    for (long long i = 0; i < 10; i++) tmp[i] = segTree[now].lazy[i];
    for (long long i = 0; i < 10; i++)
      if (segTree[now].lazy[i] == sta) tmp[i] = ed;
    for (long long i = 0; i < 10; i++) segTree[now].lazy[i] = tmp[i];
    return;
  }
  if ((segTree[now].l == segTree[now].r)) return;
  normalize(now);
  update(now << 1, segL, segR, sta, ed);
  update(now << 1 | 1, segL, segR, sta, ed);
  upt(now);
}
long long query(const long long now, const long long segL,
                const long long segR) {
  if (segR < segTree[now].l || segTree[now].r < segL) return 0;
  if (segL <= segTree[now].l && segTree[now].r <= segR) {
    long long tmp = 0;
    for (long long i = 0; i < 10; i++) tmp += 1ll * segTree[now].cnt[i] * i;
    return tmp;
  }
  if ((segTree[now].l == segTree[now].r)) return 0;
  normalize(now);
  upt(now);
  long long tmp = query(now << 1, segL, segR);
  return tmp + query(now << 1 | 1, segL, segR);
}
signed main() {
  p[0] = 1;
  for (long long i = 1; i < 10; i++) p[i] = p[i - 1] * 10;
  read(N), read(Q);
  for (long long i = 1; i <= N; i++) {
    read(a[i]);
  }
  build(1, 1, N);
  long long opt, l, r, x, y;
  for (long long i = 1; i <= Q; i++) {
    read(opt), read(l), read(r);
    if (opt & 1) {
      read(x), read(y);
      update(1, l, r, x, y);
    } else
      write(query(1, l, r)), putchar('\n');
  }
  return 0;
}
