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

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

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

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

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

l.q = c
h.x = d
h.z = l
d.r = l
d.x = c
d.w = c
d.q = h
c.q = l
c.v = l
c.u = d
assert d.r.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

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

l.q = c
h.x = d
h.z = l
d.r = l
d.x = c
d.w = c
d.q = h
c.q = l
c.v = l
c.u = d
assert d.r.q.u.txt == "d"