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

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

b = A("b")
k = B("k")
g = B("g")
c = A("c")
j = A("j")
d = A("d")
e = A("e")
f = B("f")

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

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

b = A("b")
k = B("k")
g = B("g")
c = A("c")
j = A("j")
d = A("d")
e = A("e")
f = B("f")

b.s = d
k.u = c
g.u = c
c.s = b
j.s = c
d.s = b
e.s = d
f.u = e
assert f.u.s.s.txt == "b"