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

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

n = A("n")
b = B("b")
d = B("d")
c = A("c")

n.x = c
b.w = c
d.w = c
c.x = n
assert c.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

n = A("n")
b = B("b")
d = B("d")
c = A("c")

n.x = c
b.w = c
d.w = c
c.x = n
assert c.x.x.x.x.txt == "c"