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

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

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

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

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

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

b.o = f
b.y = g
a.s = g
g.s = h
f.o = b
f.y = g
h.s = a
assert b.o.y.s.s.txt == "a"