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

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

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

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

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

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

j.v = c
j.r = h
c.r = j
c.t = h
h.v = c
h.r = j
assert j.r.r.r.txt == "h"