#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
const long long int INF = LLONG_MAX;
const long long int mod = 1e9 + 7;
void funccall(string &a, string &b, vector<long long int> &oper) {
  long long int n = a.size();
  for (long long int i = n - 1; i >= 0; i--) {
    if (a[i] == b[i]) continue;
    if (i == 0) {
      oper.push_back(1);
      continue;
    }
    char temp1, temp2;
    if (i > 1) {
      char temp1 = a[0];
      char temp2 = a[i];
      if (temp1 == '0')
        a[i] = '1';
      else
        a[i] = '0';
      if (temp2 == '0')
        a[0] = '1';
      else
        a[0] = '0';
      oper.push_back(i + 1);
    }
    if (b[i] == a[0]) {
      oper.push_back(1);
      temp1 = a[0];
      if (temp1 == '0')
        a[0] = '1';
      else
        a[0] = '0';
    }
    oper.push_back(i + 1);
    temp1 = a[0];
    temp2 = a[i];
    if (temp1 == '0')
      a[i] = '1';
    else
      a[i] = '0';
    if (temp2 == '0')
      a[0] = '1';
    else
      a[0] = '0';
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string a;
    string b;
    cin >> a;
    cin >> b;
    string var = a;
    vector<long long int> oper;
    funccall(var, b, oper);
    long long int szoper = oper.size();
    long long int count = 0;
    while (count < 10 && szoper > 2 * n) {
      var = a;
      oper.clear();
      oper.push_back(n - count);
      for (long long int i = 0; i <= n - count - 1; i++) {
        if (var[i] == '0')
          var[i] = '1';
        else
          var[i] = '0';
      }
      reverse(var.begin(), var.begin() + n - count);
      count++;
      funccall(var, b, oper);
      szoper = oper.size();
    }
    vector<long long int> final;
    long long int index = 0;
    while (index < szoper) {
      long long int tem = oper[index];
      long long int tempcount = 0;
      while (index < szoper && tem == oper[index]) {
        index++;
        tempcount++;
      }
      if (tempcount % 2 != 0) final.push_back(tem);
    }
    szoper = final.size();
    cout << szoper << " ";
    for (decltype(final.begin()) it = final.begin(); it != final.end(); it++)
      cout << *it << " ";
    cout << endl;
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
