// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define boostIO                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define rep(i, a) for (int i = 0; i < a; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, b, a) for (int i = b; i >= a; i--)
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()
#define mem(a, val) memset(a, val, sizeof(a))
#define trav(a, x) for (auto &a : x)
#define popcount(x) __builtin_popcountll(x)
#define pb push_back
#define fi first
#define se second
#define mod 998244353
#define int long long
typedef pair<int, int> pii;
const long long INF = 1e18;
const int N = 1e3 + 5;

void add(int &x, int y) {
	x = (x + y) % mod;
	x = (x + mod) % mod;
}

string x, y;
int n, m;
int dp[N][N][2];

signed main() {
    boostIO;
    cin >> x >> y;
    n = x.length();
    m = y.length();
    x.push_back('#');
    y.push_back('#');

    vector<int> sufx(n), sufy(m);
    for (int i = n - 1; i >= 0; i--) {
    	int j = i + 1;
    	while (j < n and x[j] != x[j - 1]) {
    		j++;
    	}
    	sufx[i] = j - i;
    }
    for (int i = m - 1; i >= 0; i--) {
    	int j = i + 1;
    	while (j < m and y[j] != y[j - 1]) {
    		j++;
    	}
    	sufy[i] = j - i;
    }
    for (int i = n - 1; i >= 0; i--) {
    	for (int j = m - 1; j >= 0; j--) {
    		// dp[i][j][0] and dp[i][j][1]
    		if (x[i + 1] != x[i]) add(dp[i][j][0], dp[i + 1][j][0]);
    		if (x[i] != y[j]) {
    			add(dp[i][j][0], dp[i + 1][j][1]);
    			add(dp[i][j][0], sufy[j]);
    		}
    		if (y[j + 1] != y[j]) add(dp[i][j][1], dp[i][j + 1][1]);
    		if (x[i] != y[j]) {
    			add(dp[i][j][1], dp[i][j + 1][0]);
    			add(dp[i][j][1], sufx[i]);
    		}
    	}
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
    	for (int j = 0; j < m; j++) {
    		add(ans, dp[i][j][0] + dp[i][j][1]);
    	}
    }
    cout << ans << endl;
    return 0;
}
// FRANKIE SAY RELAX... ;; editorial pretty tough one