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

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

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

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

h = A("h")
g = B("g")
c = C("c")
n = D("n")
b = B("b")

h.x = n
g.u = b
g.z = h
c.x = g
c.s = g
c.v = n
n.q = g
n.v = c
b.u = g
b.z = h
assert g.u.z.x.v.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

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

h = A("h")
g = B("g")
c = C("c")
n = D("n")
b = B("b")

h.x = n
g.u = b
g.z = h
c.x = g
c.s = g
c.v = n
n.q = g
n.v = c
b.u = g
b.z = h
assert g.u.z.x.v.x.txt == "g"