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

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

i = A("i")
m = B("m")
h = A("h")

i.x = h
i.v = h
m.w = i
h.x = i
h.v = i
assert i.x.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.v: A = None
        self.txt = txt

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

i = A("i")
m = B("m")
h = A("h")

i.x = h
i.v = h
m.w = i
h.x = i
h.v = i
assert i.x.x.v.txt == "h"