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

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

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

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

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

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

f.p = c
f.q = i
c.w = d
i.p = d
i.q = e
l.p = c
l.q = e
e.p = c
e.q = i
d.w = c
assert c.w.w.w.w.txt == "c"