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

class B:
    def __init__(self, txt: str):
        self.v: E = None
        self.p: D = None
        self.s: D = None
        self.q: C = None
        self.r: D = None
        self.txt = txt

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

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

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

d = A("d")
f = B("f")
b = C("b")
m = D("m")
h = E("h")

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

class B:
    def __init__(self, txt: str):
        self.v: E = None
        self.p: D = None
        self.s: D = None
        self.q: C = None
        self.r: D = None
        self.txt = txt

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

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

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

d = A("d")
f = B("f")
b = C("b")
m = D("m")
h = E("h")

d.r = h
f.v = h
f.p = m
f.s = m
f.r = m
f.q = b
b.y = f
b.q = f
b.w = d
b.p = d
b.z = h
m.x = f
m.u = f
m.y = b
m.w = b
h.s = b
assert b.q.r.x.q.txt == "b"