#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  vector<int> ans;
  int cnt = 0, cnt0 = 0;
  for (int i = n - 1; i >= 1; i--) {
    if (s[i] == t[i]) {
      continue;
    }
    if (s[i] == s[0])
      ;
    else {
      if (s[0] == '0')
        s[0] = '1';
      else
        s[0] = '0';
      ans.push_back(0);
    }
    for (int j = 0; j <= i; j++) {
      if (s[j] == '0')
        s[j] = '1';
      else
        s[j] = '0';
    }
    reverse(s.begin(), s.begin() + i + 1);
    ans.push_back(i);
  }
  if (s[0] != t[0]) ans.push_back(0);
  cout << (int)ans.size() << " ";
  for (auto i : ans) cout << i + 1 << " ";
  cout << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
