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

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

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

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

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

f = A("f")
m = B("m")
e = C("e")
j = D("j")
g = E("g")

f.q = e
f.y = g
m.y = j
e.p = f
j.y = e
g.s = f
assert f.q.p.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.y: E = None
        self.txt = txt

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

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

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

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

f = A("f")
m = B("m")
e = C("e")
j = D("j")
g = E("g")

f.q = e
f.y = g
m.y = j
e.p = f
j.y = e
g.s = f
assert f.q.p.y.s.txt == "f"