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

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

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

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

h = A("h")
m = B("m")
j = C("j")
f = D("f")
e = D("e")
a = B("a")
c = D("c")
g = A("g")

h.w = m
m.y = j
m.z = c
m.r = a
j.r = a
f.x = c
f.v = e
e.x = f
e.v = c
a.y = j
a.z = c
a.r = m
c.x = f
c.v = f
g.w = m
assert g.w.z.v.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

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

h = A("h")
m = B("m")
j = C("j")
f = D("f")
e = D("e")
a = B("a")
c = D("c")
g = A("g")

h.w = m
m.y = j
m.z = c
m.r = a
j.r = a
f.x = c
f.v = e
e.x = f
e.v = c
a.y = j
a.z = c
a.r = m
c.x = f
c.v = f
g.w = m
assert g.w.z.v.x.v.txt == "f"