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

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

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

e = A("e")
h = B("h")
j = C("j")
g = A("g")
c = B("c")
b = A("b")
m = B("m")
n = A("n")

e.p = g
h.x = j
h.w = e
j.v = g
j.z = m
g.p = b
c.x = j
c.w = n
b.p = e
m.x = j
m.w = b
n.p = b
assert c.x.v.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

e = A("e")
h = B("h")
j = C("j")
g = A("g")
c = B("c")
b = A("b")
m = B("m")
n = A("n")

e.p = g
h.x = j
h.w = e
j.v = g
j.z = m
g.p = b
c.x = j
c.w = n
b.p = e
m.x = j
m.w = b
n.p = b
assert c.x.v.p.p.p.txt == "g"