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

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

f = A("f")
e = B("e")
h = B("h")
a = B("a")
j = A("j")
c = B("c")

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

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

f = A("f")
e = B("e")
h = B("h")
a = B("a")
j = A("j")
c = B("c")

f.s = a
f.t = a
e.r = f
h.r = j
a.r = j
j.s = c
j.t = c
c.r = j
assert c.r.s.r.t.r.txt == "j"