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

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

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

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

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

m = A("m")
f = B("f")
g = C("g")
k = D("k")
n = E("n")

m.t = g
f.s = m
f.r = k
g.p = f
g.q = m
k.q = m
k.s = f
n.y = k
n.q = f
n.p = g
assert k.s.s.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

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

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

m = A("m")
f = B("f")
g = C("g")
k = D("k")
n = E("n")

m.t = g
f.s = m
f.r = k
g.p = f
g.q = m
k.q = m
k.s = f
n.y = k
n.q = f
n.p = g
assert k.s.s.t.txt == "g"