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

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

a = A("a")
e = B("e")
d = A("d")
j = B("j")
g = B("g")

a.u = j
a.v = g
e.o = d
d.u = j
d.v = j
j.o = d
g.o = a
assert a.u.o.v.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.v: B = None
        self.txt = txt

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

a = A("a")
e = B("e")
d = A("d")
j = B("j")
g = B("g")

a.u = j
a.v = g
e.o = d
d.u = j
d.v = j
j.o = d
g.o = a
assert a.u.o.v.txt == "j"