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

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

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

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

j = A("j")
m = B("m")
b = C("b")
g = D("g")
a = C("a")
n = B("n")
f = C("f")

j.t = m
j.q = g
m.t = j
m.z = a
b.s = f
b.p = g
b.z = g
b.t = a
g.x = f
a.s = f
a.p = g
a.z = g
a.t = b
n.t = j
n.z = a
f.s = a
f.t = a
f.p = g
f.z = g
assert g.x.z.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: D = None
        self.txt = txt

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

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

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

j = A("j")
m = B("m")
b = C("b")
g = D("g")
a = C("a")
n = B("n")
f = C("f")

j.t = m
j.q = g
m.t = j
m.z = a
b.s = f
b.p = g
b.z = g
b.t = a
g.x = f
a.s = f
a.p = g
a.z = g
a.t = b
n.t = j
n.z = a
f.s = a
f.t = a
f.p = g
f.z = g
assert g.x.z.x.z.txt == "g"