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

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

f = A("f")
m = B("m")
g = B("g")
e = A("e")

f.y = e
m.p = g
g.p = m
e.y = f
assert e.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

f = A("f")
m = B("m")
g = B("g")
e = A("e")

f.y = e
m.p = g
g.p = m
e.y = f
assert e.y.y.y.y.txt == "e"