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

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

i = A("i")
j = B("j")
l = B("l")
m = B("m")
n = A("n")

i.p = n
j.q = n
j.w = n
l.q = n
l.w = i
m.q = n
m.w = i
n.p = i
assert i.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

i = A("i")
j = B("j")
l = B("l")
m = B("m")
n = A("n")

i.p = n
j.q = n
j.w = n
l.q = n
l.w = i
m.q = n
m.w = i
n.p = i
assert i.p.p.p.p.p.txt == "n"