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

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

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

d.o = b
k.s = d
k.p = d
b.o = d
f.s = d
f.p = b
assert f.s.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

d.o = b
k.s = d
k.p = d
b.o = d
f.s = d
f.p = b
assert f.s.o.o.txt == "d"