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

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

i = A("i")
f = B("f")
c = A("c")
e = B("e")

i.r = f
f.q = e
c.r = f
e.q = f
assert c.r.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

i = A("i")
f = B("f")
c = A("c")
e = B("e")

i.r = f
f.q = e
c.r = f
e.q = f
assert c.r.q.q.txt == "f"