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

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

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

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

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

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

i.v = d
i.t = h
m.t = h
d.v = i
d.t = m
h.t = m
assert i.v.v.v.txt == "d"