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

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

i = A("i")
c = B("c")
g = B("g")
b = B("b")
d = A("d")

i.x = d
i.o = b
c.t = g
g.t = b
b.t = c
d.x = i
d.o = c
assert c.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.o: B = None
        self.txt = txt

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

i = A("i")
c = B("c")
g = B("g")
b = B("b")
d = A("d")

i.x = d
i.o = b
c.t = g
g.t = b
b.t = c
d.x = i
d.o = c
assert c.t.t.t.txt == "c"