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

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

g = A("g")
f = B("f")
n = A("n")
a = B("a")
c = B("c")
h = A("h")

g.v = h
f.y = a
f.o = a
n.v = h
a.y = f
a.o = c
c.y = f
c.o = a
h.v = g
assert h.v.v.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

g = A("g")
f = B("f")
n = A("n")
a = B("a")
c = B("c")
h = A("h")

g.v = h
f.y = a
f.o = a
n.v = h
a.y = f
a.o = c
c.y = f
c.o = a
h.v = g
assert h.v.v.v.v.v.v.txt == "h"