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

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

f = A("f")
j = B("j")
d = B("d")
m = B("m")
b = A("b")
h = B("h")

f.v = b
j.t = h
j.r = f
d.t = m
d.r = b
m.t = d
m.r = f
b.v = f
h.t = d
h.r = f
assert m.t.r.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

f = A("f")
j = B("j")
d = B("d")
m = B("m")
b = A("b")
h = B("h")

f.v = b
j.t = h
j.r = f
d.t = m
d.r = b
m.t = d
m.r = f
b.v = f
h.t = d
h.r = f
assert m.t.r.v.v.v.v.txt == "b"