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

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

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

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

m = A("m")
i = B("i")
k = C("k")
f = D("f")

m.y = k
i.w = m
k.w = i
k.p = i
k.q = m
f.y = m
f.t = k
f.w = i
f.q = i
assert i.w.y.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

m = A("m")
i = B("i")
k = C("k")
f = D("f")

m.y = k
i.w = m
k.w = i
k.p = i
k.q = m
f.y = m
f.t = k
f.w = i
f.q = i
assert i.w.y.p.w.txt == "m"