#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
vector<string> v[maxn];
void Cin(string& s, int& x) {
  char c;
  vector<int> vec;
  while (cin >> c) {
    if (c == ',' && !vec.empty()) {
      for (int i = 0; i < vec.size(); i++) {
        x += vec[i] * pow(10, vec.size() - i - 1);
      }
      return;
    }
    if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
      s.push_back(c);
    else if (c >= '0' && c <= '9') {
      vec.push_back(c - '0');
    }
  }
}
void solve(int x, int res, int& ans, int& cnt) {
  string s;
  if (!x) {
    ans = max(ans, res + 1);
    return;
  }
  res++;
  for (int i = 0; i < x; i++) {
    int y = 0;
    s.clear();
    Cin(s, y);
    solve(y, res, ans, cnt);
    v[res].push_back(s);
  }
  ans = max(ans, res);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  char c;
  int ans = 0, cnt = 0;
  string s;
  while (cin >> c) {
    int x = 0;
    s.clear();
    if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') s.push_back(c);
    Cin(s, x);
    v[0].push_back(s);
    solve(x, 0, ans, cnt);
  }
  cout << ans << '\n';
  for (int i = 0; i < ans; i++) {
    for (auto x : v[i]) cout << x << " ";
    cout << '\n';
  }
}
