#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
void solve() {
  long long n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  vector<long long> ans;
  for (long long i = n - 1; i >= 0; i--) {
    if (a[i] != b[i]) {
      if (a[0] == b[i]) {
        ans.push_back(1);
        a[0] = '0' + !(a[0] - '0');
      }
      reverse(a.begin(), a.begin() + i + 1);
      for (long long j = 0; j <= i; j++) {
        a[j] = '0' + !(a[j] - '0');
      }
      ans.push_back(i + 1);
    }
  }
  if (ans.empty() == false)
    cout << ans.size() << " ";
  else
    cout << "0"
         << " ";
  for (long long i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  ;
  while (t--) {
    solve();
  }
  return 0;
}
