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

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

f = A("f")
d = B("d")
m = B("m")
h = B("h")
n = A("n")
j = A("j")
c = A("c")

f.o = m
d.v = h
m.v = h
h.v = m
n.o = m
j.o = m
c.o = d
assert h.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

f = A("f")
d = B("d")
m = B("m")
h = B("h")
n = A("n")
j = A("j")
c = A("c")

f.o = m
d.v = h
m.v = h
h.v = m
n.o = m
j.o = m
c.o = d
assert h.v.v.v.txt == "m"