#include <bits/stdc++.h>
using namespace std;
void invert(string::iterator b, string::iterator e, string a) {
  for (; b <= e; b++) *b = (*b) ^ 1;
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  short t;
  cin >> t;
  while (t--) {
    int n;
    string a, b;
    cin >> n >> a >> b;
    vector<int> v;
    bool ok = true;
    string::iterator it = a.end() - 1;
    for (int i = n - 1; i >= 0;) {
      int j = 0, k = i;
      for (; j <= i; j++, k--) {
        if (a[j] == b[k]) break;
        if ((a[j] != b[k]) and i == 0) {
          ok = false;
          break;
        }
      }
      if (i == 0 and a[j] == b[k]) break;
      if (j == 0 and ok) {
        invert(a.begin(), a.begin(), a);
        v.push_back(1);
        if (i == 0)
          break;
        else
          continue;
      } else if (!ok) {
        invert(a.begin(), a.begin(), a);
        v.push_back(1);
        break;
      } else {
        invert(a.begin(), it, a);
        reverse(a.begin(), it + 1);
        v.push_back(it - a.begin() + 1);
        it = it - j;
        i = i - j;
        continue;
      }
    }
    cout << v.size() << " ";
    for (auto it = v.begin(); it != v.end(); it++) cout << *it << " ";
    cout << endl;
  }
}
