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

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

f = A("f")
k = B("k")
j = B("j")
c = A("c")

f.y = j
k.p = f
k.z = f
j.p = c
j.z = c
c.y = k
assert c.y.p.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

f = A("f")
k = B("k")
j = B("j")
c = A("c")

f.y = j
k.p = f
k.z = f
j.p = c
j.z = c
c.y = k
assert c.y.p.y.z.txt == "c"