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

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

d = A("d")
f = B("f")
m = B("m")

d.p = f
d.s = f
f.q = m
f.y = m
m.q = f
m.y = f
assert m.y.q.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: B = None
        self.txt = txt

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

d = A("d")
f = B("f")
m = B("m")

d.p = f
d.s = f
f.q = m
f.y = m
m.q = f
m.y = f
assert m.y.q.y.txt == "f"