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

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

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

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

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

class F:
    def __init__(self, txt: str):
        self.r: E = None
        self.txt = txt

d = A("d")
h = B("h")
m = C("m")
l = D("l")
k = E("k")
b = F("b")

d.y = l
h.r = b
m.z = b
m.x = b
m.w = l
m.p = l
l.r = m
l.z = m
l.q = b
k.p = h
k.s = h
b.r = k
assert m.w.z.p.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

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

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

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

class F:
    def __init__(self, txt: str):
        self.r: E = None
        self.txt = txt

d = A("d")
h = B("h")
m = C("m")
l = D("l")
k = E("k")
b = F("b")

d.y = l
h.r = b
m.z = b
m.x = b
m.w = l
m.p = l
l.r = m
l.z = m
l.q = b
k.p = h
k.s = h
b.r = k
assert m.w.z.p.q.r.txt == "k"