#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 3, mod1 = 1e9 + 7, inf = 3e18 + 7;
long long tc, id, n, m, a, b, c, d, i, j, k, ans;
long long mp[1004];
string A, B;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> tc;
  while (tc--) {
    cin >> n >> A >> B;
    vector<long long> vec;
    for (i = n - 1; i >= 0; i--) {
      if ((n - i) % 2)
        j = (n - i) / 2;
      else
        j = n - (n - i) / 2;
      if (B[i] - '0' == (A[j] - '0' + n - i - 1) % 2) vec.push_back(1);
      vec.push_back(i + 1);
    }
    cout << vec.size();
    string s = A;
    for (long long len : vec) cout << ' ' << len;
    cout << endl;
  }
}
