#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T qmin(const T &x, const T &y) {
  return x < y ? x : y;
}
template <typename T>
inline T qmax(const T &x, const T &y) {
  return x > y ? x : y;
}
template <typename T>
inline void getmin(T &x, const T &y) {
  if (y < x) x = y;
}
template <typename T>
inline void getmax(T &x, const T &y) {
  if (y > x) x = y;
}
inline void fileio(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const int inf = (int)1e9 + 7;
const long long linf = (long long)1e17 + 7;
const int N = 1e5 + 7, Node = N << 2;
int to[Node][10];
long long val[Node][10];
int n, q, a[N];
inline void merge(int u) {
  for (int i = 0; i < (10); ++i) val[u][i] = 0;
  for (int i = 0; i < (10); ++i) {
    val[u][to[((u) << 1)][i]] += val[((u) << 1)][i];
    val[u][to[((u) << 1 ^ 1)][i]] += val[((u) << 1 ^ 1)][i];
  }
}
inline void psd(int u) {
  for (int i = 0; i < (10); ++i) {
    to[((u) << 1)][i] = to[u][to[((u) << 1)][i]];
    to[((u) << 1 ^ 1)][i] = to[u][to[((u) << 1 ^ 1)][i]];
  }
  for (int i = 0; i < (10); ++i) to[u][i] = i;
}
inline void init(int u, int l, int r) {
  for (int i = 0; i < (10); ++i) to[u][i] = i;
  if (l == r) {
    for (int v = a[l], w = 1; v; v /= 10, w *= 10) val[u][v % 10] += w;
  } else {
    int mid = l + r >> 1;
    init(((u) << 1), l, mid);
    init(((u) << 1 ^ 1), mid + 1, r);
    merge(u);
  }
}
inline void change(int u, int l, int r, int l1, int r1, int x, int y) {
  if (l1 <= l && r <= r1) {
    for (int i = 0; i < (10); ++i)
      if (to[u][i] == x) to[u][i] = y;
  } else {
    psd(u);
    int mid = l + r >> 1;
    if (l1 <= mid) change(((u) << 1), l, mid, l1, r1, x, y);
    if (r1 > mid) change(((u) << 1 ^ 1), mid + 1, r, l1, r1, x, y);
    merge(u);
  }
}
inline long long getans(int u, int l, int r, int l1, int r1) {
  long long ans = 0;
  if (l1 <= l && r <= r1) {
    for (int i = 0; i < (10); ++i) ans += to[u][i] * val[u][i];
  } else {
    psd(u);
    int mid = l + r >> 1;
    if (l1 <= mid) ans += getans(((u) << 1), l, mid, l1, r1);
    if (r1 > mid) ans += getans(((u) << 1 ^ 1), mid + 1, r, l1, r1);
    merge(u);
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = (1); i <= (n); ++i) scanf("%d", a + i);
  init(1, 1, n);
  while (q--) {
    int type, l, r, x, y;
    scanf("%d%d%d", &type, &l, &r);
    if (type == 1) {
      scanf("%d%d", &x, &y);
      change(1, 1, n, l, r, x, y);
    } else {
      printf("%lld\n", getans(1, 1, n, l, r));
    }
  }
  return 0;
}
