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

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

h = A("h")
b = B("b")
c = B("c")
j = A("j")

h.t = b
h.v = j
b.x = j
b.w = j
c.x = h
c.w = j
j.t = b
j.v = h
assert j.t.w.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.v: A = None
        self.txt = txt

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

h = A("h")
b = B("b")
c = B("c")
j = A("j")

h.t = b
h.v = j
b.x = j
b.w = j
c.x = h
c.w = j
j.t = b
j.v = h
assert j.t.w.t.txt == "b"