#include <bits/stdc++.h>
using namespace std;
void Solve() {
  int n;
  cin >> n;
  string s, s1;
  cin >> s >> s1;
  int a[n + 1], b[n + 1];
  for (int i = 0; i < s.size(); i++) {
    a[i + 1] = s[i] - '0';
  }
  for (int i = 0; i < s1.size(); i++) {
    b[i + 1] = s1[i] - '0';
  }
  vector<int> ans;
  int toggle = 0;
  for (int i = n; i > 0; i--) {
    if (a[i] != b[i]) {
      if (a[1] == b[i]) {
        a[1] = 1 - a[1];
        ans.push_back(1);
      }
      for (int j = 2; j <= i; j++) {
        a[j] = 1 - a[j];
      }
      for (int j = 1; j <= (i / 2); j++) {
        swap(a[j], a[i - j + 1]);
      }
      ans.push_back(i);
    }
  }
  cout << ans.size() << " ";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    Solve();
  }
  return 0;
}
