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

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

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

d.r = l
g.z = j
g.y = j
i.r = d
a.r = i
j.z = g
j.y = g
l.r = i
assert d.r.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.z: B = None
        self.y: B = None
        self.txt = txt

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

d.r = l
g.z = j
g.y = j
i.r = d
a.r = i
j.z = g
j.y = g
l.r = i
assert d.r.r.r.r.txt == "l"