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

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

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

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

e = A("e")
b = B("b")
c = C("c")
a = D("a")
j = B("j")

e.p = j
b.z = j
b.t = c
b.y = a
c.w = b
a.t = e
j.z = b
j.t = c
j.y = a
assert e.p.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

e = A("e")
b = B("b")
c = C("c")
a = D("a")
j = B("j")

e.p = j
b.z = j
b.t = c
b.y = a
c.w = b
a.t = e
j.z = b
j.t = c
j.y = a
assert e.p.z.z.z.txt == "b"