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

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

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

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

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

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

i.u = m
m.p = h
m.v = h
h.p = m
h.v = m
assert i.u.v.v.txt == "m"