#include <bits/stdc++.h>
using namespace std;
const long long int M = 100 + 5, SM = 600;
const long long int inf = 1e18;
const long long int lg = 18;
const long long int z = 26;
long long int dp[M][M][M];
string dps[M][M][M];
long long int x;
long long int nxt[M][z];
long long int tt = 1;
long long int f[M];
long long int insert(string s) {
  long long int p = 0;
  for (char c : s) {
    if (nxt[p][c - 'A'] == 0) {
      nxt[p][c - 'A'] = tt++;
    }
    p = nxt[p][c - 'A'];
  }
  return p;
}
int main() {
  string s, t, virus;
  cin >> s >> t;
  long long int n = ((long long int)s.size());
  long long int m = ((long long int)t.size());
  cin >> virus;
  long long int vi = insert(virus);
  {
    queue<long long int> q;
    for (long long int i = 0; i < 26; i++) {
      if (nxt[0][i] != 0) q.push(nxt[0][i]);
    }
    while (((long long int)q.size()) > 0) {
      long long int x = q.front();
      q.pop();
      for (long long int i = 0; i < 26; i++) {
        if (nxt[x][i] == 0)
          nxt[x][i] = nxt[f[x]][i];
        else {
          f[nxt[x][i]] = nxt[f[x]][i];
          q.push(nxt[x][i]);
        }
      }
    }
  }
  for (long long int i = 1; i < n + 1; i++) {
    for (long long int j = 1; j < m + 1; j++) {
      if (s[i - 1] == t[j - 1]) {
        for (long long int k = 0; k < tt; k++) {
          long long int d = nxt[k][s[i - 1] - 'A'];
          if (k == vi || d == vi) continue;
          if (dp[i][j][d] < dp[i - 1][j - 1][k] + 1) {
            dp[i][j][d] = dp[i - 1][j - 1][k] + 1;
            dps[i][j][d] = dps[i - 1][j - 1][k] + s[i - 1];
          }
        }
      }
      for (long long int k = 0; k < tt; k++) {
        if (dp[i][j][k] < dp[i][j - 1][k]) {
          dp[i][j][k] = dp[i][j - 1][k];
          dps[i][j][k] = dps[i][j - 1][k];
        }
        if (dp[i][j][k] < dp[i - 1][j][k]) {
          dp[i][j][k] = dp[i - 1][j][k];
          dps[i][j][k] = dps[i - 1][j][k];
        }
      }
    }
  }
  long long int res = 0;
  string pes = "";
  for (long long int k = 0; k < tt; k++) {
    if (k != vi) {
      if (res < dp[n][m][k]) {
        res = dp[n][m][k];
        pes = dps[n][m][k];
      }
    }
  }
  cout << (pes == "" ? "0" : pes);
}
