#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 5000 + 4;
long long powmod(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
  }
  return res;
}
int gcd(int a, int b) {
  while (b > 0) {
    int t = a % b;
    a = b, b = t;
  }
  return a;
}
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
int is_prime(int n) {
  if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0)) return 0;
  for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
    if (n % i == 0) return 0;
  return 1;
}
long long modI(long long a, long long m) {
  long long m0 = m, y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m;
    a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long mod_inv(long long a, long long m = MOD) {
  return a == 1 ? 1 : m - mod_inv(m % a, a) * m / a;
}
long long choose(long long n, long long r) {
  long long product = 1;
  for (long long i = 0; i < r; i++)
    product = product * (n - i) % MOD * mod_inv(i + 1) % MOD;
  return product;
}
int dx[4] = {-1, +1, 0, 0};
int dy[4] = {0, 0, +1, -1};
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int> ans;
    int l = 0, r = n - 1, cnt = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (cnt % 2) {
        if (s[r] != t[i]) {
          if (cnt % 2 == 1) r++;
          continue;
        }
        if (s[l] == s[r]) {
          ans.push_back(i + 1);
          int x = l - 1;
          l = r;
          r = x;
        } else {
          ans.push_back(1);
          ans.push_back(i + 1);
          int x = l - 1;
          l = r;
          r = x;
        }
        cnt++;
      } else {
        if (s[r] == t[i]) {
          r--;
          continue;
        }
        if (s[l] == s[r]) {
          ans.push_back(i + 1);
          int x = l;
          l = r;
          r = x + 1;
        } else {
          ans.push_back(1);
          ans.push_back(i + 1);
          int x = l;
          l = r;
          r = x + 1;
        }
        cnt++;
      }
    }
    cout << ans.size() << "\n";
    ;
    for (int i : ans) cout << i << " ";
    cout << '\n';
  }
  return 0;
}
