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

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

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

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

d = A("d")
c = B("c")
m = C("m")
i = D("i")
b = C("b")
e = A("e")
j = D("j")

d.x = j
d.q = b
c.x = b
m.r = d
m.p = d
m.z = j
m.x = c
i.y = m
b.r = d
b.p = d
b.z = i
b.x = c
e.x = i
e.q = b
j.y = m
assert j.y.p.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.q: C = None
        self.txt = txt

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

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

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

d = A("d")
c = B("c")
m = C("m")
i = D("i")
b = C("b")
e = A("e")
j = D("j")

d.x = j
d.q = b
c.x = b
m.r = d
m.p = d
m.z = j
m.x = c
i.y = m
b.r = d
b.p = d
b.z = i
b.x = c
e.x = i
e.q = b
j.y = m
assert j.y.p.q.z.txt == "i"