class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.v: B = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
a = C("a")
e = D("e")

f.z = a
f.v = c
c.r = f
a.q = c
e.y = f
assert f.z.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.v: B = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
a = C("a")
e = D("e")

f.z = a
f.v = c
c.r = f
a.q = c
e.y = f
assert f.z.q.r.txt == "f"