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

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

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

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

g = A("g")
j = B("j")
d = C("d")
k = D("k")
e = A("e")

g.p = e
j.p = k
j.s = d
d.p = k
d.q = k
k.w = j
k.y = j
k.z = g
k.s = e
e.p = g
assert k.w.p.z.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

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

g = A("g")
j = B("j")
d = C("d")
k = D("k")
e = A("e")

g.p = e
j.p = k
j.s = d
d.p = k
d.q = k
k.w = j
k.y = j
k.z = g
k.s = e
e.p = g
assert k.w.p.z.p.p.txt == "g"