#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5;
int N, A[Maxn + 5];
struct SegmentTree {
  struct Segment {
    long long val[10];
    int tag[10];
  };
  Segment t[Maxn * 4 + 5];
  inline void split(int rt, int v) {
    long long now = 1;
    while (v) {
      t[rt].val[v % 10] += now;
      v /= 10, now *= 10;
    }
  }
  void pushup(int rt) {
    for (int i = 0; i < 10; i++)
      t[rt].val[i] = t[rt << 1].val[i] + t[rt << 1 | 1].val[i];
  }
  void change(int rt, int son) {
    long long t1[10];
    int t2[10];
    for (int i = 0; i < 10; i++) t1[i] = t[son].val[i], t2[i] = t[son].tag[i];
    for (int i = 0; i < 10; i++)
      if (t[rt].tag[i] != i) {
        for (int j = 0; j < 10; j++)
          if (t[son].tag[j] == i) t2[j] = t[rt].tag[i];
        t1[t[rt].tag[i]] += t[son].val[i];
        t1[i] -= t[son].val[i];
      }
    for (int i = 0; i < 10; i++) t[son].val[i] = t1[i], t[son].tag[i] = t2[i];
  }
  void pushdown(int rt) {
    change(rt, rt << 1), change(rt, rt << 1 | 1);
    for (int i = 0; i < 10; i++) t[rt].tag[i] = i;
  }
  void build(int rt, int l, int r) {
    for (int i = 0; i < 10; i++) t[rt].tag[i] = i;
    if (l == r) {
      split(rt, A[l]);
      return;
    }
    int mid = (l + r) >> 1;
    build(rt << 1, l, mid), build(rt << 1 | 1, mid + 1, r);
    pushup(rt);
  }
  void modify(int rt, int l, int r, int ml, int mr, int x, int y) {
    if (l > mr || r < ml) return;
    if (ml <= l && r <= mr) {
      for (int i = 0; i < 10; i++)
        if (t[rt].tag[i] == x) {
          t[rt].val[y] += t[rt].val[x];
          t[rt].val[x] = 0;
          t[rt].tag[i] = y;
        }
      return;
    }
    pushdown(rt);
    int mid = (l + r) >> 1;
    modify(rt << 1, l, mid, ml, mr, x, y);
    modify(rt << 1 | 1, mid + 1, r, ml, mr, x, y);
    pushup(rt);
  }
  long long query(int rt, int l, int r, int ql, int qr) {
    if (l > qr || r < ql) return 0;
    if (ql <= l && r <= qr) {
      long long ret = 0;
      for (int i = 0; i < 10; i++) ret += (i * t[rt].val[i]);
      return ret;
    }
    pushdown(rt);
    int mid = (l + r) >> 1;
    long long sum =
        query(rt << 1, l, mid, ql, qr) + query(rt << 1 | 1, mid + 1, r, ql, qr);
    pushup(rt);
    return sum;
  }
};
SegmentTree tree;
int main() {
  int Q;
  scanf("%d %d", &N, &Q);
  for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
  tree.build(1, 1, N);
  while (Q--) {
    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) continue;
      tree.modify(1, 1, N, l, r, x, y);
    }
    if (op == 2) {
      int l, r;
      scanf("%d %d", &l, &r);
      printf("%lld\n", tree.query(1, 1, N, l, r));
    }
  }
  return 0;
}
