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

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

d = A("d")
m = B("m")
f = B("f")

d.u = f
d.y = f
m.y = d
f.y = d
assert m.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.y: B = None
        self.txt = txt

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

d = A("d")
m = B("m")
f = B("f")

d.u = f
d.y = f
m.y = d
f.y = d
assert m.y.y.y.txt == "d"