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

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

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

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

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

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

c.o = f
c.s = a
f.r = c
a.r = c
g.r = c
assert f.r.s.r.txt == "c"