#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
vector<int> ans;
char s1[maxn], s2[maxn];
int n;
void op(int x) {
  for (int i = 1; i <= x; ++i) {
    s1[i] = s1[i] == '0' ? '1' : '0';
  }
  reverse(s1 + 1, s1 + 1 + x);
  ans.push_back(x);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s1 + 1 >> s2 + 1;
    ans.clear();
    for (int i = n; i >= 1; --i) {
      if (s1[i] == s2[i]) continue;
      if (i == 1)
        op(1);
      else {
        if (s1[1] == s2[i]) op(1);
        op(i);
      }
    }
    cout << ((int)ans.size());
    for (auto &v : ans) cout << " " << v;
    cout << "\n";
  }
  return 0;
}
