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

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

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

b = A("b")
e = B("e")
d = C("d")
a = C("a")
c = C("c")
m = B("m")
j = A("j")

b.p = m
b.r = j
e.p = b
e.w = d
d.z = m
d.v = e
d.y = b
a.z = e
a.v = e
a.y = b
c.z = e
c.v = e
c.y = j
m.p = j
m.w = a
j.p = m
j.r = b
assert e.p.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.r: A = None
        self.txt = txt

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

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

b = A("b")
e = B("e")
d = C("d")
a = C("a")
c = C("c")
m = B("m")
j = A("j")

b.p = m
b.r = j
e.p = b
e.w = d
d.z = m
d.v = e
d.y = b
a.z = e
a.v = e
a.y = b
c.z = e
c.v = e
c.y = j
m.p = j
m.w = a
j.p = m
j.r = b
assert e.p.r.r.txt == "b"