#include <bits/stdc++.h>
using namespace std;
int a[100005], po[10];
struct BIT {
  struct node {
    long long cnt[10];
  };
  struct node2 {
    int who[10];
  };
  vector<node> tree;
  vector<node2> lazy;
  BIT(int N) : tree(4 * N), lazy(4 * N) {
    for (int i = 0; i < tree.size(); i++) {
      for (int j = 0; j < 10; j++) {
        tree[i].cnt[j] = 0;
        lazy[i].who[j] = j;
      }
    }
  }
  void build(int x, int L, int R) {
    if (L == R) {
      for (int i = 0; i < 10; i++) {
        tree[x].cnt[a[L] % 10] += po[i];
        a[L] /= 10;
        if (a[L] == 0) break;
      }
      return;
    }
    int mid = (L + R) >> 1;
    build(x + x, L, mid);
    build(x + x + 1, mid + 1, R);
    for (int i = 0; i < 10; i++) {
      tree[x].cnt[i] = tree[x + x].cnt[i] + tree[x + x + 1].cnt[i];
    }
  }
  void push(int x, int L, int R) {
    long long cc[10] =
        {
            0,
        },
              cc2[10] = {
                  0,
              };
    for (int i = 0; i < 10; i++) {
      cc[i] = tree[x + x].cnt[i];
      cc2[i] = tree[x + x + 1].cnt[i];
      tree[x + x].cnt[i] = tree[x + x + 1].cnt[i] = 0;
    }
    for (int i = 0; i < 10; i++) {
      lazy[x + x].who[i] = lazy[x].who[lazy[x + x].who[i]];
      lazy[x + x + 1].who[i] = lazy[x].who[lazy[x + x + 1].who[i]];
      tree[x + x].cnt[lazy[x].who[i]] += cc[i];
      tree[x + x + 1].cnt[lazy[x].who[i]] += cc2[i];
    }
    for (int i = 0; i < 10; i++) lazy[x].who[i] = i;
  }
  void update(int x, int L, int R, int le, int ri, int from, int to) {
    if (ri < L || R < le) return;
    if (le <= L && R <= ri) {
      if (from == to) return;
      tree[x].cnt[to] += tree[x].cnt[from];
      tree[x].cnt[from] = 0;
      for (int i = 0; i < 10; i++) {
        int nxt = lazy[x].who[i];
        if (nxt == from) lazy[x].who[i] = to;
      }
      return;
    }
    int mid = (L + R) >> 1;
    push(x, L, R);
    update(x + x, L, mid, le, ri, from, to);
    update(x + x + 1, mid + 1, R, le, ri, from, to);
    for (int i = 0; i < 10; i++) {
      tree[x].cnt[i] = tree[x + x].cnt[i] + tree[x + x + 1].cnt[i];
    }
  }
  long long query(int x, int L, int R, int le, int ri) {
    if (ri < L || R < le) return 0;
    long long ret = 0;
    if (le <= L && R <= ri) {
      for (int i = 1; i < 10; i++) {
        ret += tree[x].cnt[i] * (long long)i;
      }
      return ret;
    }
    int mid = (L + R) >> 1;
    push(x, L, R);
    ret = query(x + x, L, mid, le, ri);
    ret += query(x + x + 1, mid + 1, R, le, ri);
    return ret;
  }
};
int n, q;
int main() {
  po[0] = 1;
  for (int i = 1; i < 10; i++) {
    po[i] = po[i - 1] * 10;
  }
  scanf("%d %d", &n, &q);
  BIT bit(n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  bit.build(1, 1, n);
  for (int l, r, x, y, ty, i = 0; i < q; i++) {
    scanf("%d %d %d", &ty, &l, &r);
    if (ty == 1) {
      scanf("%d %d", &x, &y);
      bit.update(1, 1, n, l, r, x, y);
    } else {
      long long ret = bit.query(1, 1, n, l, r);
      printf("%lld\n", ret);
    }
  }
}
