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

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

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

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

d = A("d")
c = B("c")
h = C("h")
k = D("k")

d.y = h
c.z = d
c.u = h
c.q = h
c.p = k
h.q = d
h.p = d
h.z = c
k.v = d
assert c.q.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

d = A("d")
c = B("c")
h = C("h")
k = D("k")

d.y = h
c.z = d
c.u = h
c.q = h
c.p = k
h.q = d
h.p = d
h.z = c
k.v = d
assert c.q.p.y.txt == "h"