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

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

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

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

h = A("h")
n = B("n")
l = C("l")
f = D("f")
j = D("j")
e = C("e")
g = B("g")
m = C("m")
b = D("b")
d = D("d")

h.q = m
h.x = e
h.u = n
h.p = n
n.p = h
n.t = h
n.u = f
l.p = g
f.r = h
f.u = n
j.r = h
j.u = n
e.p = g
g.p = h
g.t = h
g.u = f
m.p = n
b.r = h
b.u = n
d.r = h
d.u = n
assert f.r.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.x: C = None
        self.u: B = None
        self.p: B = None
        self.txt = txt

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

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

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

h = A("h")
n = B("n")
l = C("l")
f = D("f")
j = D("j")
e = C("e")
g = B("g")
m = C("m")
b = D("b")
d = D("d")

h.q = m
h.x = e
h.u = n
h.p = n
n.p = h
n.t = h
n.u = f
l.p = g
f.r = h
f.u = n
j.r = h
j.u = n
e.p = g
g.p = h
g.t = h
g.u = f
m.p = n
b.r = h
b.u = n
d.r = h
d.u = n
assert f.r.x.p.txt == "g"