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