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

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

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

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

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

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

k.u = c
k.z = g
c.y = k
g.u = c
g.z = k
f.y = g
assert g.u.y.u.txt == "c"