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

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

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

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

e = A("e")
h = B("h")
g = C("g")
m = D("m")
b = A("b")
d = B("d")
i = D("i")
f = A("f")

e.r = g
e.x = g
e.p = d
h.w = g
g.z = i
g.r = h
g.v = b
m.v = g
b.r = g
b.x = g
b.p = d
d.w = g
i.v = g
f.r = g
f.x = g
f.p = d
assert h.w.z.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.p: B = None
        self.x: C = None
        self.txt = txt

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

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

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

e = A("e")
h = B("h")
g = C("g")
m = D("m")
b = A("b")
d = B("d")
i = D("i")
f = A("f")

e.r = g
e.x = g
e.p = d
h.w = g
g.z = i
g.r = h
g.v = b
m.v = g
b.r = g
b.x = g
b.p = d
d.w = g
i.v = g
f.r = g
f.x = g
f.p = d
assert h.w.z.v.v.txt == "b"