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

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

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

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

b = A("b")
e = B("e")
g = C("g")
f = D("f")
n = A("n")
j = B("j")
k = B("k")

b.z = n
b.q = f
b.r = f
e.p = k
e.z = k
g.t = b
f.q = g
f.u = g
n.z = b
n.q = f
n.r = f
j.p = e
j.z = k
k.p = j
k.z = j
assert n.z.q.q.t.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.q: D = None
        self.r: D = None
        self.txt = txt

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

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

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

b = A("b")
e = B("e")
g = C("g")
f = D("f")
n = A("n")
j = B("j")
k = B("k")

b.z = n
b.q = f
b.r = f
e.p = k
e.z = k
g.t = b
f.q = g
f.u = g
n.z = b
n.q = f
n.r = f
j.p = e
j.z = k
k.p = j
k.z = j
assert n.z.q.q.t.z.z.z.txt == "n"