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

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

h = A("h")
i = B("i")
j = A("j")
m = A("m")
n = A("n")
d = A("d")
c = A("c")

h.s = c
i.q = m
j.s = d
m.s = d
n.s = m
d.s = j
c.s = d
assert c.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

h = A("h")
i = B("i")
j = A("j")
m = A("m")
n = A("n")
d = A("d")
c = A("c")

h.s = c
i.q = m
j.s = d
m.s = d
n.s = m
d.s = j
c.s = d
assert c.s.s.s.s.txt == "j"