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

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

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

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

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

h.v = g
h.z = g
h.x = g
h.r = i
g.q = i
g.y = i
g.z = i
g.u = h
i.p = h
i.x = k
i.u = k
k.z = h
assert h.x.y.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.z: B = None
        self.r: C = None
        self.x: B = None
        self.txt = txt

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

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

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

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

h.v = g
h.z = g
h.x = g
h.r = i
g.q = i
g.y = i
g.z = i
g.u = h
i.p = h
i.x = k
i.u = k
k.z = h
assert h.x.y.x.z.txt == "h"