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

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

i = A("i")
g = B("g")
e = A("e")
h = B("h")

i.z = e
g.x = h
e.z = i
h.x = g
assert i.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

i = A("i")
g = B("g")
e = A("e")
h = B("h")

i.z = e
g.x = h
e.z = i
h.x = g
assert i.z.z.z.z.txt == "i"