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

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

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

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

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

g.q = j
g.u = n
i.z = j
b.w = g
n.x = g
n.r = i
n.y = i
j.z = i
e.q = i
e.u = n
assert j.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.u: D = None
        self.txt = txt

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

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

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

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

g.q = j
g.u = n
i.z = j
b.w = g
n.x = g
n.r = i
n.y = i
j.z = i
e.q = i
e.u = n
assert j.z.z.z.z.txt == "j"