#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
typedef long long ll;
using namespace std;

const int N = 1001;
const int mod = 998244353;

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

int solve(bool use1, bool use2, int prev, int l1, int l2) {
	if(!use1 && !use2)
		return 1;
	int& ret = dp[use1][use2][prev][l1][l2];
	if(ret != -1)
		return ret;
	char prevc = '`';
	switch (prev) {
		case 1:
			prevc = s1[l1 - 1];
			break;
		case 2:
			prevc = s2[l2 - 1];
			break;
	}
	ret = 0;
	if(use1 && l1 < n && s1[l1] != prevc) {
		ret = (ret + solve(true, use2, 1, l1 + 1, l2)) % mod;
		ret = (ret + solve(false, use2, 1, l1 + 1, l2)) % mod;
	}
	if(use2 && l2 < m && s2[l2] != prevc) {
		ret = (ret + solve(use1, true, 2, l1, l2 + 1)) % mod;
		ret = (ret + solve(use1, false, 2, l1, l2 + 1)) % mod;
	}
	return ret;
}

int main(){
    IOS

    memset(dp, -1, sizeof(dp));
    cin >> s1 >> s2;
    n = s1.length();
    m = s2.length();
    int ans = 0;
    for(int i = 0; i < n; ++i) {
    	for(int j = 0; j < m; ++j) {
    		x = i, y = j;
    		ans = (ans + solve(true, true, 0, i, j)) % mod;
    	}
    }
    cout << ans;

    return 0;
}