#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const int maxn = 1e5 + 10, maxm = 1e3 + 10, lg = 17, mod = 1e9 + 7, inf = 1e18;
struct node {
  int mxm, pre, suf;
  bool por;
  node(int mxm = 0, int pre = 0, int suf = 0, bool por = 0)
      : mxm(mxm), pre(pre), suf(suf), por(por) {}
} seg[maxn << 1];
int n, q, T[maxn], L[maxn], R[maxn], B[maxn], BB[maxn][2], ans[maxn];
string s[maxn];
vector<int> cum;
int lcp(string &a, string &b) {
  for (int i = 0; i < (int)(a.size()) && i < (int)(b.size()); i++)
    if (a[i] != b[i]) return i;
  return min((int)(a.size()), (int)(b.size()));
}
node mrg(node &n1, node &n2) {
  return node(max({n1.mxm, n2.mxm, n1.suf + n2.pre}), n1.pre + n1.por * n2.pre,
              n2.suf + n2.por * n1.suf, n1.por & n2.por);
}
void goz(int i, bool b) {
  seg[i += n] = node(b, b, b, b);
  for (i >>= 1; i; i >>= 1) seg[i] = mrg(seg[(i << 1)], seg[((i << 1) ^ 1)]);
}
int boz(int l, int r) {
  node lef = {0, 0, 0, 1}, rig = {0, 0, 0, 1};
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) lef = mrg(lef, seg[l++]);
    if (r & 1) rig = mrg(seg[--r], rig);
  }
  return mrg(lef, rig).mxm;
}
int kirnamoosankir[maxn << 1];
void gozkiri(int i, int x) {
  for (kirnamoosankir[i += n] = x; i > 1; i >>= 1)
    kirnamoosankir[i >> 1] = max(kirnamoosankir[i], kirnamoosankir[i ^ 1]);
}
int getkiri(int l, int r) {
  int ret = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) ret = max(ret, kirnamoosankir[l++]);
    if (r & 1) ret = max(ret, kirnamoosankir[--r]);
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> s[i], gozkiri(i, (int)(s[i].size()));
  for (int i = n - 1; i >= 1; i--)
    B[i] = lcp(s[i], s[i + 1]), cum.push_back(B[i]);
  for (int i = 0; i < q; i++) {
    cin >> T[i] >> L[i];
    if (T[i] == 1)
      cin >> R[i], ans[i] = getkiri(L[i], R[i] + 1);
    else
      cin >> s[L[i]], gozkiri(L[i], (int)(s[L[i]].size())),
          BB[i][0] = lcp(s[L[i] - 1], s[L[i]]),
          BB[i][1] = lcp(s[L[i]], s[L[i] + 1]), cum.push_back(BB[i][0]),
          cum.push_back(BB[i][1]);
  }
  sort(cum.begin(), cum.end()),
      cum.resize(unique(cum.begin(), cum.end()) - cum.begin());
  for (auto h : cum)
    if (h != 0) {
      for (int i = 1; i < n; i++) goz(i, B[i] >= h);
      for (int i = 0; i < q; i++) {
        if (T[i] == 1) {
          int kirkharnadaribekharbokontookoonetmike = boz(L[i], R[i]);
          if (kirkharnadaribekharbokontookoonetmike)
            kirkharnadaribekharbokontookoonetmike++;
          ans[i] = max(ans[i], kirkharnadaribekharbokontookoonetmike * h);
        } else {
          if (L[i] - 1) goz(L[i] - 1, BB[i][0] >= h);
          if (L[i] < n) goz(L[i], BB[i][1] >= h);
        }
      }
    }
  for (int i = 0; i < q; i++)
    if (T[i] == 1) cout << ans[i] << '\n';
  return 0;
}
