#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p) % p;
}
void change(long long int a[], long long int r) {
  for (long long int i = 1; i <= r; i++) {
    a[i] = a[i] ^ 1;
  }
  reverse(a + 1, a + r + 1);
}
void solve() {
  long long int n;
  cin >> n;
  char c;
  long long int a[n + 1], b[n + 1];
  for (long long int i = 1; i <= n; i++) {
    cin >> c;
    if (c == '1')
      a[i] = 1;
    else
      a[i] = 0;
  }
  for (long long int i = 1; i <= n; i++) {
    cin >> c;
    if (c == '1')
      b[i] = 1;
    else
      b[i] = 0;
  }
  vector<long long int> ans;
  long long int count = 0;
  long long int l = 1, r = n;
  for (long long int i = n; i >= 1; i--) {
    if (count & 1) {
      a[r] = a[r] ^ 1;
      if (a[r] ^ 1 != b[i]) {
        ans.push_back(1);
      }
      ans.push_back(i);
      count++;
      r--;
    } else {
      count++;
      if (a[l] ^ 1 != b[i]) {
        ans.push_back(1);
      }
      ans.push_back(i);
      l++;
    }
  }
  cout << ans.size() << " ";
  for (auto e : ans) cout << e << ' ';
  cout << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
