#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    int last = n;
    vector<int> ans;
    while (last != 0) {
      if (a[last - 1] == b[last - 1])
        --last;
      else {
        if (a[0] == b[last - 1]) {
          a[0] = 97 - a[0];
          ans.push_back(1);
        }
        ans.push_back(last);
        for (int i = 0; i < last; ++i) a[i] = 97 - a[i];
        reverse(a.begin(), a.begin() + last);
      }
    }
    cout << ans.size() << " ";
    for (auto it : ans) cout << it << " ";
    cout << '\n';
  }
  return 0;
}
