#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string str1, str2;
    cin >> str1 >> str2;
    vector<int> ans;
    for (int i = n - 1; i >= 1; i--) {
      if (str1[i] == str2[i]) continue;
      if (str1[0] == str2[i]) {
        ans.push_back(1);
        ans.push_back(i + 1);
        ans.push_back(i);
      } else {
        ans.push_back(i + 1);
        ans.push_back(i);
      }
      str1 = str1.substr(1, str1.length());
    }
    if (str1[0] != str2[0]) ans.push_back(1);
    cout << ans.size() << " ";
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
    cout << endl;
  }
}
