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

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

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

h = A("h")
m = B("m")
j = C("j")
k = A("k")
l = A("l")
c = A("c")

h.p = k
h.x = c
m.z = l
m.u = j
m.q = k
j.v = m
j.r = m
k.p = l
k.x = h
l.p = h
l.x = k
c.p = h
c.x = h
assert c.x.x.x.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.x: A = None
        self.txt = txt

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

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

h = A("h")
m = B("m")
j = C("j")
k = A("k")
l = A("l")
c = A("c")

h.p = k
h.x = c
m.z = l
m.u = j
m.q = k
j.v = m
j.r = m
k.p = l
k.x = h
l.p = h
l.x = k
c.p = h
c.x = h
assert c.x.x.x.p.p.p.txt == "h"