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

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

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

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

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

f.w = d
f.r = g
g.u = f
g.q = h
g.v = d
d.x = f
d.z = h
d.u = m
d.q = m
h.t = m
h.v = d
a.u = f
a.q = h
a.v = d
m.t = h
m.v = d
assert a.v.z.v.z.t.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.r: B = None
        self.txt = txt

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

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

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

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

f.w = d
f.r = g
g.u = f
g.q = h
g.v = d
d.x = f
d.z = h
d.u = m
d.q = m
h.t = m
h.v = d
a.u = f
a.q = h
a.v = d
m.t = h
m.v = d
assert a.v.z.v.z.t.v.txt == "d"