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

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

g = A("g")
h = B("h")
k = B("k")
m = A("m")

g.v = h
h.t = g
k.t = m
m.v = h
assert h.t.v.t.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

g = A("g")
h = B("h")
k = B("k")
m = A("m")

g.v = h
h.t = g
k.t = m
m.v = h
assert h.t.v.t.txt == "g"