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

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

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

a.r = e
d.y = c
d.q = e
e.r = a
b.r = e
c.y = d
c.q = e
i.y = l
i.q = e
l.y = c
l.q = e
assert b.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

a.r = e
d.y = c
d.q = e
e.r = a
b.r = e
c.y = d
c.q = e
i.y = l
i.q = e
l.y = c
l.q = e
assert b.r.r.r.txt == "e"