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

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

class C:
    def __init__(self, txt: str):
        self.w: B = None
        self.q: D = None
        self.y: B = None
        self.z: A = None
        self.txt = txt

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

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

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

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

class C:
    def __init__(self, txt: str):
        self.w: B = None
        self.q: D = None
        self.y: B = None
        self.z: A = None
        self.txt = txt

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

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

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