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

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

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

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

f = A("f")
d = B("d")
b = C("b")
a = D("a")
k = D("k")
j = C("j")
h = B("h")
m = A("m")

f.w = h
f.x = d
d.v = h
d.p = h
d.q = f
b.r = m
a.z = d
k.z = h
j.r = f
h.v = d
h.p = d
h.q = m
m.w = d
m.x = d
assert f.w.p.q.x.q.x.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.x: B = None
        self.txt = txt

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

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

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

f = A("f")
d = B("d")
b = C("b")
a = D("a")
k = D("k")
j = C("j")
h = B("h")
m = A("m")

f.w = h
f.x = d
d.v = h
d.p = h
d.q = f
b.r = m
a.z = d
k.z = h
j.r = f
h.v = d
h.p = d
h.q = m
m.w = d
m.x = d
assert f.w.p.q.x.q.x.v.q.txt == "m"