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

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

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

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

n = A("n")
f = B("f")
e = C("e")
h = D("h")

n.r = h
n.y = f
n.z = f
n.q = f
f.y = h
f.r = h
f.q = e
e.v = f
h.u = n
h.v = e
assert e.v.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.y: B = None
        self.z: B = None
        self.q: B = None
        self.txt = txt

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

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

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

n = A("n")
f = B("f")
e = C("e")
h = D("h")

n.r = h
n.y = f
n.z = f
n.q = f
f.y = h
f.r = h
f.q = e
e.v = f
h.u = n
h.v = e
assert e.v.q.v.txt == "f"