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

class B:
    def __init__(self, txt: str):
        self.p: D = None
        self.t: A = None
        self.txt = txt

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

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

n = A("n")
h = B("h")
i = C("i")
g = D("g")

n.o = i
n.x = g
n.y = g
h.p = g
h.t = n
i.u = n
i.p = n
i.v = h
i.s = h
g.z = h
assert n.o.v.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.x: D = None
        self.y: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: D = None
        self.t: A = None
        self.txt = txt

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

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

n = A("n")
h = B("h")
i = C("i")
g = D("g")

n.o = i
n.x = g
n.y = g
h.p = g
h.t = n
i.u = n
i.p = n
i.v = h
i.s = h
g.z = h
assert n.o.v.p.z.txt == "h"