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

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

d = A("d")
m = B("m")
f = B("f")
e = A("e")
j = B("j")
g = A("g")

d.u = m
m.o = d
m.s = e
f.o = g
f.s = e
e.u = f
j.o = g
j.s = e
g.u = f
assert m.s.u.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

d = A("d")
m = B("m")
f = B("f")
e = A("e")
j = B("j")
g = A("g")

d.u = m
m.o = d
m.s = e
f.o = g
f.s = e
e.u = f
j.o = g
j.s = e
g.u = f
assert m.s.u.s.txt == "e"