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.txt = txt

c = A("c")
k = B("k")
h = B("h")
a = B("a")
g = A("g")

c.o = g
k.s = g
h.s = c
a.s = c
g.o = c
assert a.s.o.o.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.txt = txt

c = A("c")
k = B("k")
h = B("h")
a = B("a")
g = A("g")

c.o = g
k.s = g
h.s = c
a.s = c
g.o = c
assert a.s.o.o.o.o.txt == "c"