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

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

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

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

a = A("a")
n = B("n")
g = C("g")
f = D("f")
h = C("h")

a.x = n
n.q = g
n.v = g
n.s = h
n.u = f
g.s = n
g.q = h
g.t = f
g.p = f
f.z = a
f.q = a
h.s = n
h.q = g
h.t = f
h.p = f
assert g.t.z.x.s.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

a = A("a")
n = B("n")
g = C("g")
f = D("f")
h = C("h")

a.x = n
n.q = g
n.v = g
n.s = h
n.u = f
g.s = n
g.q = h
g.t = f
g.p = f
f.z = a
f.q = a
h.s = n
h.q = g
h.t = f
h.p = f
assert g.t.z.x.s.t.txt == "f"