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

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

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

c = A("c")
e = B("e")
i = C("i")
m = B("m")
j = C("j")
f = A("f")

c.y = i
c.x = m
e.r = c
e.w = m
i.y = e
m.r = f
m.w = e
j.y = m
f.y = j
f.x = e
assert e.r.x.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.x: B = None
        self.txt = txt

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

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

c = A("c")
e = B("e")
i = C("i")
m = B("m")
j = C("j")
f = A("f")

c.y = i
c.x = m
e.r = c
e.w = m
i.y = e
m.r = f
m.w = e
j.y = m
f.y = j
f.x = e
assert e.r.x.r.x.txt == "e"