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

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

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

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

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

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

a.y = f
a.z = f
k.v = a
k.p = e
e.y = f
e.z = a
d.v = e
d.p = a
f.y = e
f.z = e
assert f.y.y.y.txt == "e"