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

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

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

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

a = A("a")
f = B("f")
m = C("m")
j = D("j")
k = D("k")
g = B("g")

a.w = m
a.r = j
f.x = m
f.u = a
m.v = a
j.p = k
j.y = f
k.p = j
k.y = g
g.x = m
g.u = a
assert m.v.w.v.w.v.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.r: D = None
        self.txt = txt

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

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

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

a = A("a")
f = B("f")
m = C("m")
j = D("j")
k = D("k")
g = B("g")

a.w = m
a.r = j
f.x = m
f.u = a
m.v = a
j.p = k
j.y = f
k.p = j
k.y = g
g.x = m
g.u = a
assert m.v.w.v.w.v.w.txt == "m"