#include <bits/stdc++.h>
using namespace std;
vector<long long> ans;
void modify(string &s, long long pos) {
  for (long long i = 0; i < pos; i++) {
    if (s[i] == '0')
      s[i] = '1';
    else
      s[i] = '0';
  }
  for (long long i = 0; i < pos / 2; i++) swap(s[i], s[pos - i - 1]);
}
int main() {
  long long t;
  cin >> t;
  for (long long o = 0; o < t; o++) {
    long long n;
    cin >> n;
    ans.clear();
    string a, b;
    cin >> a >> b;
    for (long long i = n - 1; i > 0; i--) {
      if (a[i] == b[i]) continue;
      if (a[0] == b[i]) {
        modify(a, 1);
        ans.push_back(1);
      }
      modify(a, i + 1);
      ans.push_back(i + 1);
    }
    if (a[0] != b[0]) ans.push_back(1);
    cout << ans.size();
    for (long long i = 0; i < ans.size(); i++) cout << ' ' << ans[i];
    cout << '\n';
  }
}
