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

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

c = A("c")
g = B("g")
d = B("d")
b = B("b")
h = A("h")
n = A("n")
e = A("e")
j = A("j")

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

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

c = A("c")
g = B("g")
d = B("d")
b = B("b")
h = A("h")
n = A("n")
e = A("e")
j = A("j")

c.v = b
g.o = n
g.w = h
d.o = j
d.w = j
b.o = n
b.w = j
h.v = g
n.v = g
e.v = g
j.v = b
assert c.v.w.v.txt == "b"