#include <bits/stdc++.h>
using namespace std;
void rev(string &s, int p) {
  for (int i = 0; i < p; i++) s[i] ^= 1;
  reverse(s.begin(), s.begin() + p);
}
void solve() {
  int n;
  string a, b;
  cin >> n >> a >> b;
  vector<int> ans;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] == b[i]) continue;
    if (a[0] != b[i]) {
      ans.push_back(i + 1);
      rev(a, i + 1);
    } else {
      ans.push_back(1);
      ans.push_back(i + 1);
      rev(a, 1);
      rev(a, i + 1);
    }
  }
  cout << ans.size();
  for (int x : ans) cout << " " << x;
  cout << "\n";
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) solve();
}
