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

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

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

class D:
    def __init__(self, txt: str):
        self.w: B = None
        self.s: E = None
        self.z: A = None
        self.p: C = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

b = A("b")
m = B("m")
i = C("i")
d = D("d")
e = E("e")
g = F("g")
k = D("k")

b.v = e
m.r = d
m.z = b
m.v = b
m.w = e
i.x = k
d.w = m
d.s = e
d.z = b
d.p = i
e.q = m
g.p = e
g.q = m
k.w = m
k.s = e
k.z = b
k.p = i
assert m.w.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.v: E = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.w: B = None
        self.s: E = None
        self.z: A = None
        self.p: C = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

b = A("b")
m = B("m")
i = C("i")
d = D("d")
e = E("e")
g = F("g")
k = D("k")

b.v = e
m.r = d
m.z = b
m.v = b
m.w = e
i.x = k
d.w = m
d.s = e
d.z = b
d.p = i
e.q = m
g.p = e
g.q = m
k.w = m
k.s = e
k.z = b
k.p = i
assert m.w.q.z.txt == "b"