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

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

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

c.o = i
h.r = i
i.o = c
a.o = c
g.r = c
assert a.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.r: A = None
        self.txt = txt

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

c.o = i
h.r = i
i.o = c
a.o = c
g.r = c
assert a.o.o.o.txt == "c"