#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int32_t x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
char myHeap[200 * 1024 * 1024];
long long sz = 0;
void assert_tle(bool q) {
  while (!q)
    ;
}
void *operator new(std::size_t count) {
  sz += count;
  assert_tle(sz <= 200 * 1024 * 1024);
  return myHeap + sz - count;
}
void operator delete(void *ptr) {}
void fastIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  long long n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  vector<long long> ans;
  long long e = 0, o = n - 1;
  for (long long i = n - 1; i >= 0; i--) {
    long long turn = n - i - 1;
    long long cur;
    if (turn % 2 == 0) {
      cur = e;
      e++;
      if (a[cur] != b[i]) {
        ans.push_back(i + 1);
      } else {
        ans.push_back(1);
        ans.push_back(i + 1);
      }
    } else {
      cur = o;
      o--;
      if (a[cur] == b[i]) {
        ans.push_back(i + 1);
      } else {
        ans.push_back(1);
        ans.push_back(i + 1);
      }
    }
  }
  cout << ans.size() << " ";
  for (auto it : ans) cout << it << " ";
}
int32_t main() {
  fastIO();
  long long t;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
