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

i = A("i")
b = B("b")
a = A("a")
d = A("d")
e = B("e")

i.r = e
i.u = a
b.v = d
a.r = e
a.u = i
d.r = e
d.u = a
e.v = a
assert a.r.v.u.u.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.v: A = None
        self.txt = txt

i = A("i")
b = B("b")
a = A("a")
d = A("d")
e = B("e")

i.r = e
i.u = a
b.v = d
a.r = e
a.u = i
d.r = e
d.u = a
e.v = a
assert a.r.v.u.u.txt == "a"