class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.x: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

f = A("f")
e = B("e")
k = B("k")
c = B("c")
j = A("j")
h = A("h")
a = B("a")
g = B("g")
m = A("m")
b = A("b")

f.u = h
f.x = b
e.s = a
k.s = e
c.s = a
j.u = b
j.x = f
h.u = m
h.x = f
a.s = e
g.s = a
m.u = j
m.x = b
b.u = h
b.x = j
assert a.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.x: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

f = A("f")
e = B("e")
k = B("k")
c = B("c")
j = A("j")
h = A("h")
a = B("a")
g = B("g")
m = A("m")
b = A("b")

f.u = h
f.x = b
e.s = a
k.s = e
c.s = a
j.u = b
j.x = f
h.u = m
h.x = f
a.s = e
g.s = a
m.u = j
m.x = b
b.u = h
b.x = j
assert a.s.s.s.s.txt == "a"