#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int p = 1, ret = 0;
  while ((c < '0') || (c > '9')) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while ((c >= '0') && (c <= '9'))
    ret = (ret << 1) + (ret << 3) + c - '0', c = getchar();
  return ret * p;
}
int n, m;
int jc[11];
int a[100005];
long long tmp[10];
struct tree {
  int t[10];
  long long sum[10];
  void mod(int x, int y) {
    sum[y] += sum[x];
    sum[x] = 0;
    for (int i = 0; i < 10; i++)
      if (t[i] == x) t[i] = y;
  }
} t[400005];
void pushup(int index) {
  for (int i = 0; i < 10; i++)
    t[index].sum[i] = t[index << 1].sum[i] + t[index << 1 | 1].sum[i];
}
void build(int l, int r, int index) {
  for (int i = 0; i < 10; i++) t[index].t[i] = i;
  if (l == r) {
    for (int i = 0; i < 9; i++)
      if (a[l] >= jc[i]) t[index].sum[a[l] / jc[i] % 10] += jc[i];
    return;
  }
  build(l, ((l + r) >> 1), index << 1);
  build(((l + r) >> 1) + 1, r, index << 1 | 1);
  pushup(index);
}
void pushdown(int index) {
  for (int i = 0; i < 10; i++)
    tmp[i] = t[index << 1].sum[i], t[index << 1].sum[i] = 0;
  for (int i = 0; i < 10; i++) {
    t[index << 1].sum[t[index].t[i]] += tmp[i];
    t[index << 1].t[i] = t[index].t[t[index << 1].t[i]];
  }
  for (int i = 0; i < 10; i++)
    tmp[i] = t[index << 1 | 1].sum[i], t[index << 1 | 1].sum[i] = 0;
  for (int i = 0; i < 10; i++) {
    t[index << 1 | 1].sum[t[index].t[i]] += tmp[i];
    t[index << 1 | 1].t[i] = t[index].t[t[index << 1 | 1].t[i]];
  }
  for (int i = 0; i < 10; i++) t[index].t[i] = i;
}
void modify(int l, int r, int L, int R, int x, int y, int index) {
  if ((L <= l) && (R >= r)) {
    t[index].mod(x, y);
    return;
  }
  pushdown(index);
  if (L <= ((l + r) >> 1)) modify(l, ((l + r) >> 1), L, R, x, y, index << 1);
  if (R > ((l + r) >> 1))
    modify(((l + r) >> 1) + 1, r, L, R, x, y, index << 1 | 1);
  pushup(index);
}
inline tree query(int l, int r, int L, int R, int index) {
  if ((L <= l) && (R >= r)) return t[index];
  pushdown(index);
  if (R <= ((l + r) >> 1)) return query(l, ((l + r) >> 1), L, R, index << 1);
  if (L > ((l + r) >> 1))
    return query(((l + r) >> 1) + 1, r, L, R, index << 1 | 1);
  tree tmp, tmp1 = query(l, ((l + r) >> 1), L, R, index << 1),
            tmp2 = query(((l + r) >> 1) + 1, r, L, R, index << 1 | 1);
  for (int i = 0; i < 10; i++) tmp.sum[i] = tmp1.sum[i] + tmp2.sum[i];
  return tmp;
}
int main() {
  jc[0] = 1;
  for (int i = 1; i < 9; i++) jc[i] = jc[i - 1] * 10;
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  build(1, n, 1);
  while (m--) {
    int flag = read();
    if (flag == 1) {
      int l = read(), r = read(), x = read(), y = read();
      if (x == y) continue;
      modify(1, n, l, r, x, y, 1);
    } else {
      int l = read(), r = read();
      long long ans = 0;
      tree tmp = query(1, n, l, r, 1);
      for (int i = 1; i < 10; i++) ans += tmp.sum[i] * i;
      printf("%I64d\n", ans);
    }
  }
}
