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

e = A("e")
g = B("g")
k = A("k")
c = A("c")

e.x = g
g.y = c
k.x = g
c.x = g
assert k.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

e = A("e")
g = B("g")
k = A("k")
c = A("c")

e.x = g
g.y = c
k.x = g
c.x = g
assert k.x.y.x.y.txt == "c"