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

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

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

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

n = A("n")
h = B("h")
a = C("a")
l = D("l")

n.v = h
n.z = h
n.r = a
h.q = n
a.w = h
a.y = n
l.r = h
l.z = h
l.p = n
l.q = a
assert l.z.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.z: B = None
        self.r: C = None
        self.txt = txt

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

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

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

n = A("n")
h = B("h")
a = C("a")
l = D("l")

n.v = h
n.z = h
n.r = a
h.q = n
a.w = h
a.y = n
l.r = h
l.z = h
l.p = n
l.q = a
assert l.z.q.v.txt == "h"