#include <bits/stdc++.h>
using namespace std;
void prl(long long x) { cout << x << '\n'; }
void speed() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void checker() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void transform(string &s, int ind) {
  for (int i = 0; i <= ind; i++) {
    s[i] ^= 1;
  }
  reverse(s.begin(), s.begin() + ind + 1);
}
void solve() {
  vector<int> moves;
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  int done = n - 1;
  for (int i = 0; i < n; i++) {
    if (b[done] == '0') {
      if (a[0] == '1') {
        transform(a, done);
        moves.push_back(done + 1);
      } else {
        transform(a, 0);
        moves.push_back(1);
        transform(a, done);
        moves.push_back(done + 1);
      }
    }
    if (b[done] == '1') {
      if (a[0] == '0') {
        transform(a, done);
        moves.push_back(done + 1);
      } else {
        transform(a, 0);
        moves.push_back(1);
        transform(a, done);
        moves.push_back(done + 1);
      }
    }
    done--;
  }
  cout << moves.size() << " ";
  for (auto it : moves) cout << it << " ";
  cout << '\n';
  ;
}
int main() {
  speed();
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
}
