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

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

c = A("c")
m = B("m")
g = B("g")
i = A("i")

c.x = m
m.y = c
g.y = c
i.x = m
assert c.x.y.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

c = A("c")
m = B("m")
g = B("g")
i = A("i")

c.x = m
m.y = c
g.y = c
i.x = m
assert c.x.y.x.y.txt == "c"