#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb emplace_back
#define mp make_pair
#define sqr(n) ((n)*(n))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define precision(a) setiosflags(ios::fixed) << setprecision(a)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef double db;
 
template <typename T> inline char read(T &x) {
    x = 0; T fg = 1; char ch = getchar();
    while (!isdigit(ch)) {if (ch == '-') fg = -1;ch = getchar();}
    while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar();
    x = fg * x; return ch;
}
template <typename T, typename... Args> inline void read(T &x, Args &... args) { read(x), read(args...); }
template <typename T> inline void write(T x) {
    int len = 0; char c[21]; if (x < 0) putchar('-'), x = -x;
    do{++len; c[len] = x % 10 + '0';} while (x /= 10);
    for (int i = len; i >= 1; i--) putchar(c[i]);
}
template <typename T, typename... Args> inline void write(T& x, Args &... args) { write(x), write(args...); }
 
template<class T1, class T2> bool umin(T1& a, T2 b) { return a > b ? (a = b, true) : false; }
template<class T1, class T2> bool umax(T1& a, T2 b) { return a < b ? (a = b, true) : false; }
template<class T> void clear(T& a) { T().swap(a); }
 
const int N = 1e3 + 5, mod = 998244353;
 
int n, m, _, k, cas;
ll a[N][N], b[N][N], ans;
char s[N], t[N];
 
int main() {
    IOS; cin >> s + 1 >> t + 1;
    for (int i = 1; s[i]; ++i) a[i][0] = (s[i] == s[i - 1] ? 0 : a[i - 1][0]) + 1;
    for (int i = 1; t[i]; ++i) b[0][i] = (t[i] == t[i - 1] ? 0 : b[0][i - 1]) + 1;
    for (int i = 1; s[i]; ++i) for(int j = 1; t[j]; ++j) {
        if (s[i] ^ s[i - 1]) a[i][j] = a[i - 1][j];
        if (t[j] ^ t[j - 1]) b[i][j] = b[i][j - 1];
        if (s[i] ^ t[j]) {
            a[i][j] = (a[i][j] + b[i - 1][j]) % mod;
            if (i - 1) a[i][j] = (a[i][j] + b[0][j]) % mod;
            b[i][j] = (b[i][j] + a[i][j - 1]) % mod;
            if (j - 1) b[i][j] = (b[i][j] + a[i][0]) % mod;
        }
        ans = (ans + a[i][j] + b[i][j]) % mod;
    }
    cout << ans; 
    return 0;
}