#include <bits/stdc++.h>
using namespace std;
const int N = int(1e5) + 10, mod = int(1e9) + 7;
int n, q, que, req;
int a[N];
long long t[4 * N][11];
int mdf[4 * N][11], tim[4 * N][12], p[12];
inline void build(int v, int l, int r) {
  for (int i = 0; i < 10; i++) {
    mdf[v][i] = i;
  }
  if (l == r) {
    int x = a[l];
    int res = 1;
    while (x > 0) {
      t[v][x % 10] += res;
      x /= 10;
      res *= 10;
    }
    return;
  }
  int m = (l + r) >> 1;
  build(v + v, l, m);
  build(v + v + 1, m + 1, r);
  for (int d = 0; d < 10; d++) {
    t[v][d] = t[v + v][d] + t[v + v + 1][d];
  }
}
long long sum1[12], sum2[12];
inline void push(int v) {
  memset(sum1, 0, sizeof(sum1));
  memset(sum2, 0, sizeof(sum2));
  for (int i = 0; i < 10; i++) {
    sum1[mdf[v][i]] += t[v + v][i];
    sum2[mdf[v][i]] += t[v + v + 1][i];
  }
  for (int i = 0; i < 10; i++) {
    mdf[v + v][i] = mdf[v][mdf[v + v][i]];
    mdf[v + v + 1][i] = mdf[v][mdf[v + v + 1][i]];
  }
  for (int i = 0; i < 10; i++) {
    mdf[v][i] = i;
    t[v + v][i] = sum1[i];
    t[v + v + 1][i] = sum2[i];
  }
}
inline void upd(int v, int tl, int tr, int l, int r, int x, int y) {
  if (tl > r || l > tr) return;
  if (l <= tl && tr <= r) {
    for (int i = 0; i < 10; i++) {
      if (mdf[v][i] == x) {
        mdf[v][i] = y;
      }
    }
    t[v][y] += t[v][x];
    t[v][x] = 0;
    return;
  }
  int tm = (tl + tr) >> 1;
  push(v);
  upd(v + v, tl, tm, l, r, x, y);
  upd(v + v + 1, tm + 1, tr, l, r, x, y);
  for (int d = 0; d < 10; d++) {
    t[v][d] = t[v + v][d] + t[v + v + 1][d];
  }
}
inline long long get(int v, int tl, int tr, int l, int r) {
  if (tl > r || l > tr) return 0;
  if (l <= tl && tr <= r) {
    long long res = 0;
    for (int d = 0; d < 10; d++) {
      res += 1ll * d * t[v][d];
    }
    return res;
  }
  int tm = (tl + tr) >> 1;
  push(v);
  return get(v + v, tl, tm, l, r) + get(v + v + 1, tm + 1, tr, l, r);
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i <= 9; i++) p[i] = i;
  build(1, 1, n);
  for (int i = 1, tp, l, r, x, y; i <= q; i++) {
    scanf("%d%d%d", &tp, &l, &r);
    if (tp == 1) {
      scanf("%d%d", &x, &y);
      que = i;
      if (x != y) upd(1, 1, n, l, r, x, y);
    } else {
      printf("%lld\n", get(1, 1, n, l, r));
    }
  }
  return 0;
}
