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

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

a = A("a")
k = B("k")
b = A("b")
f = A("f")
g = B("g")

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

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

a = A("a")
k = B("k")
b = A("b")
f = A("f")
g = B("g")

a.p = g
k.s = g
k.o = b
b.p = k
f.p = k
g.s = k
g.o = b
assert b.p.o.p.txt == "k"