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

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

e = A("e")
i = B("i")
l = C("l")
d = B("d")
f = A("f")

e.r = f
i.z = d
i.y = e
l.y = f
l.x = f
l.q = d
d.z = i
d.y = f
f.r = e
assert d.y.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: A = None
        self.txt = txt

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

e = A("e")
i = B("i")
l = C("l")
d = B("d")
f = A("f")

e.r = f
i.z = d
i.y = e
l.y = f
l.x = f
l.q = d
d.z = i
d.y = f
f.r = e
assert d.y.r.r.r.txt == "e"