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

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

c = A("c")
g = B("g")
d = A("d")
a = B("a")

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

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

c = A("c")
g = B("g")
d = A("d")
a = B("a")

c.o = a
g.p = a
g.s = c
d.o = g
a.p = g
a.s = c
assert a.p.p.s.txt == "c"