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

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

class C:
    def __init__(self, txt: str):
        self.u: D = None
        self.y: B = None
        self.p: B = None
        self.txt = txt

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

h = A("h")
m = B("m")
g = C("g")
n = D("n")
d = D("d")
k = A("k")

h.x = g
h.s = m
m.x = g
m.s = d
m.r = k
g.u = n
g.y = m
g.p = m
n.y = h
n.v = d
n.q = m
d.y = k
d.v = n
d.q = m
k.x = g
k.s = m
assert g.p.r.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.s: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.u: D = None
        self.y: B = None
        self.p: B = None
        self.txt = txt

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

h = A("h")
m = B("m")
g = C("g")
n = D("n")
d = D("d")
k = A("k")

h.x = g
h.s = m
m.x = g
m.s = d
m.r = k
g.u = n
g.y = m
g.p = m
n.y = h
n.v = d
n.q = m
d.y = k
d.v = n
d.q = m
k.x = g
k.s = m
assert g.p.r.x.p.txt == "m"