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.u: A = None
        self.txt = txt

e = A("e")
j = B("j")
h = B("h")
g = B("g")
d = A("d")

e.u = g
j.o = e
j.u = e
h.o = d
h.u = e
g.o = d
g.u = d
d.u = h
assert e.u.u.u.o.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.u: A = None
        self.txt = txt

e = A("e")
j = B("j")
h = B("h")
g = B("g")
d = A("d")

e.u = g
j.o = e
j.u = e
h.o = d
h.u = e
g.o = d
g.u = d
d.u = h
assert e.u.u.u.o.txt == "d"