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

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

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

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

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

e.p = b
b.t = g
b.z = j
j.q = e
j.r = g
j.z = g
g.r = j
g.t = b
assert e.p.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

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

e.p = b
b.t = g
b.z = j
j.q = e
j.r = g
j.z = g
g.r = j
g.t = b
assert e.p.t.t.t.txt == "g"