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

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

j = A("j")
g = B("g")
d = A("d")
e = B("e")
i = A("i")
a = A("a")

j.r = e
j.u = a
g.o = j
d.r = g
d.u = i
e.o = a
i.r = e
i.u = a
a.r = g
a.u = i
assert a.u.u.u.r.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: A = None
        self.txt = txt

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

j = A("j")
g = B("g")
d = A("d")
e = B("e")
i = A("i")
a = A("a")

j.r = e
j.u = a
g.o = j
d.r = g
d.u = i
e.o = a
i.r = e
i.u = a
a.r = g
a.u = i
assert a.u.u.u.r.o.txt == "a"