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

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

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

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

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

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

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

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

j.p = k
j.v = e
c.x = k
c.w = g
g.o = m
m.x = b
m.w = g
k.p = j
k.v = m
e.x = b
e.w = g
b.p = k
b.v = m
assert j.p.p.v.w.o.x.p.txt == "k"