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

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

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

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

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

h = A("h")
j = B("j")
b = C("b")
m = D("m")
g = E("g")

h.x = b
j.r = g
j.w = h
j.y = h
j.p = b
b.t = m
m.q = j
g.p = b
g.r = b
g.z = b
g.s = h
assert j.y.x.t.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

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

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

h = A("h")
j = B("j")
b = C("b")
m = D("m")
g = E("g")

h.x = b
j.r = g
j.w = h
j.y = h
j.p = b
b.t = m
m.q = j
g.p = b
g.r = b
g.z = b
g.s = h
assert j.y.x.t.q.p.txt == "b"