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

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

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

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

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

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

k.p = l
k.q = f
l.s = f
l.x = f
b.p = f
b.q = l
f.s = l
f.x = l
assert f.s.x.s.s.txt == "f"