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

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

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

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

g = A("g")
n = B("n")
d = C("d")
j = D("j")
b = A("b")

g.t = j
g.w = d
g.z = d
n.s = b
n.x = b
n.y = d
d.z = b
d.t = g
j.q = d
j.z = d
j.y = n
b.t = j
b.w = d
b.z = d
assert j.y.x.z.z.w.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.w: C = None
        self.z: C = None
        self.txt = txt

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

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

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

g = A("g")
n = B("n")
d = C("d")
j = D("j")
b = A("b")

g.t = j
g.w = d
g.z = d
n.s = b
n.x = b
n.y = d
d.z = b
d.t = g
j.q = d
j.z = d
j.y = n
b.t = j
b.w = d
b.z = d
assert j.y.x.z.z.w.txt == "d"