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

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

f = A("f")
k = B("k")
l = B("l")

f.p = k
k.q = l
l.q = k
assert l.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

f = A("f")
k = B("k")
l = B("l")

f.p = k
k.q = l
l.q = k
assert l.q.q.q.txt == "k"