#include <bits/stdc++.h>
int pos = 1 << 17;
char buf[1 << 17];
inline char nextch() {
  if (pos == 1 << 17) fread(buf, 1 << 17, 1, stdin), pos = 0;
  return buf[pos++];
}
inline int read() {
  int x = 0;
  char ch = nextch();
  while (!isdigit(ch)) ch = nextch();
  while (isdigit(ch)) {
    x = 10 * x + ch - '0';
    ch = nextch();
  }
  return x;
}
std::vector<int> g[10];
int a[100000 + 1];
struct node {
  long long coef[10];
  int t[10];
} aint[265000];
int u[10], v[10];
long long s[10];
int left, right, valx, valy;
long long ans;
inline void push(int p, int st, int dr) {
  if (st < dr) {
    for (int i = 0; i < 10; i++) {
      u[i] = aint[p].t[aint[2 * p].t[i]];
      v[i] = aint[p].t[aint[2 * p + 1].t[i]];
    }
    for (int i = 0; i < 10; i++) {
      aint[2 * p].t[i] = u[i];
      aint[2 * p + 1].t[i] = v[i];
    }
  }
  for (int i = 0; i < 10; i++) s[aint[p].t[i]] += aint[p].coef[i];
  for (int i = 0; i < 10; i++) {
    aint[p].coef[i] = s[i];
    s[i] = 0;
    aint[p].t[i] = i;
  }
}
void dfs(int p, int st, int dr) {
  for (int i = 0; i < 10; i++) aint[p].t[i] = i;
  if (st == dr) {
    int x = 1;
    while (a[st] > 0) {
      aint[p].coef[a[st] % 10] += x;
      x *= 10;
      a[st] /= 10;
    }
  } else {
    int m = (st + dr) / 2;
    dfs(2 * p, st, m);
    dfs(2 * p + 1, m + 1, dr);
    for (int i = 0; i < 10; i++)
      aint[p].coef[i] = aint[2 * p].coef[i] + aint[2 * p + 1].coef[i];
  }
}
void update(int p, int st, int dr) {
  push(p, st, dr);
  if ((right < st) || (dr < left)) return;
  if ((left <= st) && (dr <= right)) {
    aint[p].t[valx] = valy;
    push(p, st, dr);
  } else {
    int m = (st + dr) / 2;
    update(2 * p, st, m);
    update(2 * p + 1, m + 1, dr);
    for (int i = 0; i < 10; i++)
      aint[p].coef[i] = aint[2 * p].coef[i] + aint[2 * p + 1].coef[i];
  }
}
void query(int p, int st, int dr) {
  push(p, st, dr);
  if ((right < st) || (dr < left)) return;
  if ((left <= st) && (dr <= right)) {
    for (int i = 0; i < 10; i++) ans += aint[p].coef[i] * i;
  } else {
    int m = (st + dr) / 2;
    query(2 * p, st, m);
    query(2 * p + 1, m + 1, dr);
    for (int i = 0; i < 10; i++)
      aint[p].coef[i] = aint[2 * p].coef[i] + aint[2 * p + 1].coef[i];
  }
}
int main() {
  int n = read();
  int q = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  dfs(1, 1, n);
  for (int i = 1; i <= q; i++) {
    int t = read();
    left = read();
    right = read();
    if (t == 1) {
      valx = read();
      valy = read();
      if (valx != valy) update(1, 1, n);
    } else {
      ans = 0;
      query(1, 1, n);
      fprintf(stdout, "%I64d\n", ans);
    }
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
