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

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

e = A("e")
k = B("k")
a = B("a")
d = A("d")

e.p = k
k.z = d
a.z = d
d.p = k
assert d.p.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

e = A("e")
k = B("k")
a = B("a")
d = A("d")

e.p = k
k.z = d
a.z = d
d.p = k
assert d.p.z.p.txt == "k"