#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
string s1, s2, virus;
struct KnuthMorrisPratt {
  int link[N];
  int skip[N][26];
  void clear() {
    memset(link, 0, sizeof link);
    memset(skip, 0, sizeof skip);
  }
  KnuthMorrisPratt() { clear(); }
  KnuthMorrisPratt(string S) {
    clear();
    for (int i = int(2); i < int(S.size()); i++) {
      link[i] = link[i - 1];
      while (link[i] > 0 && S[link[i] + 1] != S[i]) link[i] = link[link[i]];
      if (S[link[i] + 1] == S[i]) link[i]++;
    }
    for (int c = int(0); c < int(26); c++)
      skip[0][c] = 0, skip[(int)S.size() - 1][c] = -1;
    skip[0][S[1] - 'A'] = 1;
    for (int i = int(1); i < int((int)S.size() - 1); i++) {
      for (int c = int(0); c < int(26); c++)
        if (S[i + 1] - 'A' == c)
          skip[i][c] = i + 1;
        else
          skip[i][c] = skip[link[i]][c];
    }
  }
} kmp;
int dp[N][N][N];
struct Data {
  int x, y, z;
  char c;
} trace[N][N][N];
bool maximize(int &a, int b) {
  if (a > b) return 0;
  a = b;
  return 1;
}
void solve() {
  dp[0][0][0] = 1;
  for (int i = int(0); i < int(s1.size()); i++)
    for (int j = int(0); j < int(s2.size()); j++)
      for (int k = int(0); k < int(virus.size() - 1); k++) {
        if (dp[i][j][k] == 0) continue;
        bool f1 = (i + 1 < s1.size());
        bool f2 = (j + 1 < s2.size());
        if (f1 && f2 && s1[i + 1] == s2[j + 1])
          if (maximize(dp[i + 1][j + 1][kmp.skip[k][s1[i + 1] - 'A']],
                       dp[i][j][k] + 1))
            trace[i + 1][j + 1][kmp.skip[k][s1[i + 1] - 'A']] = {i, j, k,
                                                                 s1[i + 1]};
        if (f1)
          if (maximize(dp[i + 1][j][k], dp[i][j][k]))
            trace[i + 1][j][k] = {i, j, k, '\0'};
        if (f2)
          if (maximize(dp[i][j + 1][k], dp[i][j][k]))
            trace[i][j + 1][k] = {i, j, k, '\0'};
      }
  int bestMatch = 0;
  int x = s1.size() - 1, y = s2.size() - 1;
  for (int i = int(1); i < int(virus.size() - 1); i++)
    if (dp[x][y][i] > dp[x][y][bestMatch]) bestMatch = i;
  string result = "";
  bool flag = 1;
  while (x > 0 && y > 0) {
    Data pre = trace[x][y][bestMatch];
    if (pre.c != '\0') result = pre.c + result;
    x = pre.x, y = pre.y, bestMatch = pre.z;
  }
  if (result.empty()) result = "0";
  cout << result << '\n';
}
int main() {
  cin >> s1 >> s2 >> virus;
  s1 = " " + s1;
  s2 = " " + s2;
  virus = " " + virus;
  kmp = KnuthMorrisPratt(virus);
  solve();
}
