#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int to[maxn << 2][10];
long long cnt[maxn << 2][10];
int n, m;
long long a[maxn], t[12];
void up(int rt) {
  for (int i = (0); i < (10); ++i)
    cnt[rt][i] = cnt[rt << 1][i] + cnt[rt << 1 | 1][i];
  return;
}
void down(int rt) {
  memset(t, 0, sizeof t);
  for (int i = (0); i < (10); ++i)
    t[to[rt][i]] += cnt[rt << 1][i], to[rt << 1][i] = to[rt][to[rt << 1][i]];
  for (int i = (0); i < (10); ++i) cnt[rt << 1][i] = t[i];
  memset(t, 0, sizeof t);
  for (int i = (0); i < (10); ++i)
    t[to[rt][i]] += cnt[rt << 1 | 1][i],
        to[rt << 1 | 1][i] = to[rt][to[rt << 1 | 1][i]];
  for (int i = (0); i < (10); ++i) cnt[rt << 1 | 1][i] = t[i];
  for (int i = (0); i < (10); ++i) to[rt][i] = i;
}
void build(int rt, int l, int r) {
  for (int i = (0); i < (10); ++i) to[rt][i] = i;
  if (l == r) {
    int num = 0;
    int x = a[l];
    while (x) t[num++] = x % 10, x /= 10;
    long long cur = 1;
    for (int i = (0); i < (num); ++i) cnt[rt][t[i]] += cur, cur *= 10;
    return;
  }
  build(rt << 1, l, ((l + r) >> 1));
  build(rt << 1 | 1, ((l + r) >> 1) + 1, r);
  up(rt);
}
void update(int rt, int l, int r, int L, int R, int x, int y) {
  if (L <= l && r <= R) {
    cnt[rt][y] += cnt[rt][x];
    cnt[rt][x] = 0;
    for (int i = (0); i < (10); ++i)
      if (to[rt][i] == x) to[rt][i] = y;
    return;
  }
  down(rt);
  if (L <= ((l + r) >> 1)) update(rt << 1, l, ((l + r) >> 1), L, R, x, y);
  if (R > ((l + r) >> 1))
    update(rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R, x, y);
  up(rt);
  return;
}
long long qry(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    long long res = 0;
    for (int i = (1); i < (10); ++i) res += (long long)i * cnt[rt][i];
    return res;
  }
  down(rt);
  long long res = 0;
  if (L <= ((l + r) >> 1)) res += qry(rt << 1, l, ((l + r) >> 1), L, R);
  if (R > ((l + r) >> 1)) res += qry(rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R);
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = (1); i < (n + 1); ++i) scanf("%lld", &a[i]);
  build(1, 1, n);
  while (m--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int l, r, x, y;
      scanf("%d%d%d%d", &l, &r, &x, &y);
      if (x != y) update(1, 1, n, l, r, x, y);
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      printf("%lld\n", qry(1, 1, n, l, r));
    }
  }
  return 0;
}
