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

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

h = A("h")
g = B("g")
b = B("b")
f = A("f")
a = A("a")

h.v = a
g.o = f
g.r = a
b.o = a
b.r = f
f.v = a
a.v = f
assert a.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.o: A = None
        self.r: A = None
        self.txt = txt

h = A("h")
g = B("g")
b = B("b")
f = A("f")
a = A("a")

h.v = a
g.o = f
g.r = a
b.o = a
b.r = f
f.v = a
a.v = f
assert a.v.v.v.txt == "f"