#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
long long int sum[N << 2][11], sum2[11], a[N];
int lazy[N << 2][11], vis[11];
void pushdown(int rt) {
  for (int i = 0; i < 10; i++)
    vis[i] = lazy[rt << 1][i], sum2[i] = sum[rt << 1][i];
  for (int i = 0; i < 10; i++)
    if (lazy[rt][i] != i) {
      for (int j = 0; j < 10; j++)
        if (lazy[rt << 1][j] == i) vis[j] = lazy[rt][i];
      sum2[lazy[rt][i]] += sum[rt << 1][i];
      sum2[i] -= sum[rt << 1][i];
    }
  for (int i = 0; i < 10; i++)
    sum[rt << 1][i] = sum2[i], lazy[rt << 1][i] = vis[i];
  for (int i = 0; i < 10; i++)
    vis[i] = lazy[rt << 1 | 1][i], sum2[i] = sum[rt << 1 | 1][i];
  for (int i = 0; i < 10; i++)
    if (lazy[rt][i] != i) {
      for (int j = 0; j < 10; j++)
        if (lazy[rt << 1 | 1][j] == i) vis[j] = lazy[rt][i];
      sum2[lazy[rt][i]] += sum[rt << 1 | 1][i];
      sum2[i] -= sum[rt << 1 | 1][i];
    }
  for (int i = 0; i < 10; i++)
    sum[rt << 1 | 1][i] = sum2[i], lazy[rt << 1 | 1][i] = vis[i];
  for (int i = 0; i < 10; i++) lazy[rt][i] = i;
}
void pushup(int rt) {
  for (int i = 0; i < 10; i++)
    sum[rt][i] = sum[rt << 1][i] + sum[rt << 1 | 1][i];
}
void build(int rt, int l, int r) {
  for (int i = 0; i < 10; i++) sum[rt][i] = 0;
  for (int i = 0; i < 10; i++) lazy[rt][i] = i;
  if (l == r) {
    for (long long int t = 1; a[l]; a[l] /= 10, t *= 10)
      sum[rt][a[l] % 10] += t;
    return;
  }
  int m = r + l >> 1;
  build(rt << 1, l, m);
  build(rt << 1 | 1, m + 1, r);
  pushup(rt);
}
void update(int rt, int l, int r, int L, int R, int x, int y) {
  if (L <= l && r <= R) {
    for (int i = 0; i < 10; i++)
      if (lazy[rt][i] == x) {
        sum[rt][y] += sum[rt][x];
        sum[rt][x] = 0;
        lazy[rt][i] = y;
      }
    return;
  }
  pushdown(rt);
  int m = r + l >> 1;
  if (L <= m) update(rt << 1, l, m, L, R, x, y);
  if (R > m) update(rt << 1 | 1, m + 1, r, L, R, x, y);
  pushup(rt);
}
long long int query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    long long int ans = 0;
    for (long long int i = 1; i < 10; i++) ans += sum[rt][i] * i;
    return ans;
  }
  pushdown(rt);
  int m = r + l >> 1;
  long long int ans = 0;
  if (L <= m) ans += query(rt << 1, l, m, L, R);
  if (R > m) ans += query(rt << 1 | 1, m + 1, r, L, R);
  pushup(rt);
  return ans;
}
int n, m;
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    build(1, 1, n);
    int op, l, r, x, y;
    for (int i = 1; i <= m; i++) {
      scanf("%d%d%d", &op, &l, &r);
      if (1 == op) {
        scanf("%d%d", &x, &y);
        if (x == y) continue;
        update(1, 1, n, l, r, x, y);
      } else
        printf("%lld\n", query(1, 1, n, l, r));
    }
  }
  return 0;
}
