#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int S = 80;
int n, m, a[N];
string s[N];
struct item {
  int sum, suf[S + 1], pref[S + 1], ans;
  item(int x) {
    x = min(x, S);
    for (int i = 0; i <= S; i++) {
      suf[i] = pref[i] = (i <= x);
    }
    ans = x;
    sum = 1;
  }
  item() {
    ans = sum = 0;
    memset(suf, 0, sizeof(suf));
    memset(pref, 0, sizeof(pref));
  }
};
item t[4 * N];
inline item mrg(item a, item b) {
  item c;
  c.ans = max(a.ans, b.ans);
  c.sum = a.sum + b.sum;
  for (int i = 0; i <= S; i++) {
    c.pref[i] = a.pref[i];
    if (a.pref[i] == a.sum) {
      c.pref[i] += b.pref[i];
    }
    c.suf[i] = b.suf[i];
    if (b.suf[i] == b.sum) {
      c.suf[i] += a.suf[i];
    }
    if (a.suf[i] > 0 || b.pref[i] > 0) {
      c.ans = max(c.ans, i * (a.suf[i] + b.pref[i] + 1));
    }
  }
  return c;
}
void update(int v, int l, int r, int pos, int val) {
  if (l == r) {
    t[v] = item(val);
    return;
  }
  int mid = (r + l) >> 1;
  if (pos <= mid) {
    update(v + v, l, mid, pos, val);
  } else {
    update(v + v + 1, mid + 1, r, pos, val);
  }
  t[v] = mrg(t[v + v], t[v + v + 1]);
}
item get(int v, int l, int r, int tl, int tr) {
  if (l > r || l > tr || tl > r) {
    return item();
  }
  if (tl <= l && r <= tr) {
    return t[v];
  }
  int mid = (r + l) >> 1;
  return mrg(get(v + v, l, mid, tl, tr), get(v + v + 1, mid + 1, r, tl, tr));
}
set<int> q;
int st[4 * N], le[4 * N], ri[4 * N];
inline int lcp(int x, int y) {
  int cur = 0;
  while (cur < (int)s[x].size() && cur < (int)s[y].size() &&
         s[x][cur] == s[y][cur]) {
    cur += 1;
  }
  return cur;
}
int f[4 * N];
int gett(int v, int l, int r, int tl, int tr) {
  if (l > r || l > tr || tl > r) {
    return 0;
  }
  if (tl <= l && r <= tr) {
    return f[v];
  }
  int mid = (r + l) >> 1;
  return max(gett(v + v, l, mid, tl, tr), gett(v + v + 1, mid + 1, r, tl, tr));
}
void upd(int v, int l, int r, int pos, int val) {
  if (l == r) {
    f[v] = val;
    return;
  }
  int mid = (r + l) >> 1;
  if (pos <= mid) {
    upd(v + v, l, mid, pos, val);
  } else {
    upd(v + v + 1, mid + 1, r, pos, val);
  }
  f[v] = max(f[v + v], f[v + v + 1]);
}
void add(int pos) {
  a[pos] = lcp(pos, pos + 1);
  update(1, 1, n, pos, a[pos]);
  if (a[pos] > S) {
    q.insert(pos);
  }
}
void del(int pos) { q.erase(pos); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    upd(1, 1, n, i, (int)s[i].size());
  }
  for (int i = 1; i + 1 <= n; i++) {
    add(i);
  }
  while (m--) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r;
      cin >> l >> r;
      if (l == r) {
        cout << (int)s[l].size() << "\n";
        continue;
      }
      int ans = max(get(1, 1, n, l, r - 1).ans, gett(1, 1, n, l, r));
      int prv = -1, sz = 0;
      for (auto it = q.lower_bound(l); it != q.lower_bound(r); it++) {
        if (*it - 1 != prv) {
          st[++sz] = 0;
        }
        prv = *it;
        st[++sz] = a[prv];
      }
      vector<int> z;
      st[0] = st[sz + 1] = -1e9;
      z.push_back(0);
      for (int i = 1; i <= sz; i++) {
        while (!z.empty() && st[z.back()] >= st[i]) {
          z.pop_back();
        }
        le[i] = z.back();
        z.push_back(i);
      }
      z.clear();
      z.push_back(sz + 1);
      for (int i = sz; i >= 1; i--) {
        while (!z.empty() && st[z.back()] >= st[i]) {
          z.pop_back();
        }
        ri[i] = z.back();
        ans = max(ans, (ri[i] - le[i]) * st[i]);
        z.push_back(i);
      }
      cout << ans << "\n";
    } else {
      int x;
      string y;
      cin >> x >> y;
      if (x - 1 >= 1) {
        del(x - 1);
      }
      if (x + 1 <= n) {
        del(x);
      }
      s[x] = y;
      upd(1, 1, n, x, (int)s[x].size());
      if (x - 1 >= 1) {
        add(x - 1);
      }
      if (x + 1 <= n) {
        add(x);
      }
    }
  }
}
