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

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

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

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

i = A("i")
a = B("a")
n = C("n")
d = D("d")
f = D("f")
m = D("m")
j = C("j")
b = C("b")

i.x = d
a.q = i
n.u = i
n.s = d
n.y = f
d.z = a
d.p = m
d.q = m
f.z = a
f.p = m
f.q = m
m.z = a
m.p = f
m.q = d
j.u = i
j.s = d
j.y = m
b.u = i
b.s = f
b.y = f
assert a.q.x.z.q.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

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

i = A("i")
a = B("a")
n = C("n")
d = D("d")
f = D("f")
m = D("m")
j = C("j")
b = C("b")

i.x = d
a.q = i
n.u = i
n.s = d
n.y = f
d.z = a
d.p = m
d.q = m
f.z = a
f.p = m
f.q = m
m.z = a
m.p = f
m.q = d
j.u = i
j.s = d
j.y = m
b.u = i
b.s = f
b.y = f
assert a.q.x.z.q.x.z.txt == "a"