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

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

j = A("j")
f = B("f")
i = A("i")
e = A("e")
m = B("m")

j.q = i
f.r = e
f.s = i
i.q = j
e.q = j
m.r = i
m.s = j
assert e.q.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.r: A = None
        self.s: A = None
        self.txt = txt

j = A("j")
f = B("f")
i = A("i")
e = A("e")
m = B("m")

j.q = i
f.r = e
f.s = i
i.q = j
e.q = j
m.r = i
m.s = j
assert e.q.q.q.q.txt == "i"