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

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

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

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

g = A("g")
k = B("k")
a = C("a")
n = D("n")
f = D("f")
d = C("d")
c = A("c")
i = B("i")

g.v = i
g.s = c
k.p = a
k.u = g
a.x = i
n.z = a
f.z = d
d.x = k
c.v = i
c.s = g
i.p = d
i.u = g
assert g.v.u.s.v.u.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.s: A = None
        self.txt = txt

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

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

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

g = A("g")
k = B("k")
a = C("a")
n = D("n")
f = D("f")
d = C("d")
c = A("c")
i = B("i")

g.v = i
g.s = c
k.p = a
k.u = g
a.x = i
n.z = a
f.z = d
d.x = k
c.v = i
c.s = g
i.p = d
i.u = g
assert g.v.u.s.v.u.txt == "g"