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

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

c = A("c")
a = B("a")
d = B("d")
b = A("b")
j = B("j")

c.u = b
a.v = b
a.u = c
d.v = b
d.u = b
b.u = c
j.v = c
j.u = b
assert d.v.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

c = A("c")
a = B("a")
d = B("d")
b = A("b")
j = B("j")

c.u = b
a.v = b
a.u = c
d.v = b
d.u = b
b.u = c
j.v = c
j.u = b
assert d.v.u.u.txt == "b"