class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.p: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

a.x = m
a.p = c
f.y = c
f.t = c
c.q = f
c.s = f
m.v = c
assert c.q.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.p: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

a.x = m
a.p = c
f.y = c
f.t = c
c.q = f
c.s = f
m.v = c
assert c.q.t.q.txt == "f"