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

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

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

a = A("a")
j = B("j")
b = C("b")
n = B("n")
i = B("i")
k = B("k")
d = B("d")
g = C("g")

a.u = b
a.z = b
j.u = b
j.x = g
j.p = i
b.q = n
n.u = g
n.x = g
n.p = i
i.u = b
i.x = g
i.p = n
k.u = g
k.x = g
k.p = d
d.u = g
d.x = b
d.p = i
g.q = d
assert d.p.u.q.x.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.z: C = None
        self.txt = txt

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

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

a = A("a")
j = B("j")
b = C("b")
n = B("n")
i = B("i")
k = B("k")
d = B("d")
g = C("g")

a.u = b
a.z = b
j.u = b
j.x = g
j.p = i
b.q = n
n.u = g
n.x = g
n.p = i
i.u = b
i.x = g
i.p = n
k.u = g
k.x = g
k.p = d
d.u = g
d.x = b
d.p = i
g.q = d
assert d.p.u.q.x.q.p.txt == "i"