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

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

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

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

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

h = A("h")
e = B("e")
c = C("c")
d = D("d")
m = E("m")
g = E("g")
f = C("f")

h.s = c
e.r = d
c.q = g
d.q = m
m.r = e
g.r = e
f.q = m
assert c.q.r.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

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

h = A("h")
e = B("e")
c = C("c")
d = D("d")
m = E("m")
g = E("g")
f = C("f")

h.s = c
e.r = d
c.q = g
d.q = m
m.r = e
g.r = e
f.q = m
assert c.q.r.r.q.txt == "m"