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

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

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

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

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

d.q = i
n.y = c
i.z = d
f.x = j
f.y = c
a.x = n
a.y = d
c.q = i
j.y = d
assert c.q.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

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

d.q = i
n.y = c
i.z = d
f.x = j
f.y = c
a.x = n
a.y = d
c.q = i
j.y = d
assert c.q.z.q.z.txt == "d"