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

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

m = A("m")
n = B("n")
e = B("e")
j = B("j")
c = A("c")
f = B("f")

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

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

m = A("m")
n = B("n")
e = B("e")
j = B("j")
c = A("c")
f = B("f")

m.q = c
n.s = c
e.s = c
j.s = c
c.q = m
f.s = m
assert j.s.q.q.q.txt == "m"