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

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

class C:
    def __init__(self, txt: str):
        self.v: A = None
        self.s: A = None
        self.txt = txt

e = A("e")
m = B("m")
b = C("b")
i = B("i")
a = A("a")

e.x = b
e.p = i
m.r = b
b.v = e
b.s = e
i.r = b
a.x = b
a.p = m
assert a.x.s.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.p: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.v: A = None
        self.s: A = None
        self.txt = txt

e = A("e")
m = B("m")
b = C("b")
i = B("i")
a = A("a")

e.x = b
e.p = i
m.r = b
b.v = e
b.s = e
i.r = b
a.x = b
a.p = m
assert a.x.s.x.s.txt == "e"